Skip to content

Commit 07b791c

Browse files
committed
Fixed bugs in protocol and with call_property function. Added tests for call_property
1 parent 382d35f commit 07b791c

File tree

6 files changed

+61
-11
lines changed

6 files changed

+61
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.15.2-dev
2+
* Bug fixes
3+
* Fixed protocol implementations for Integer and Float which where not recognized
4+
* Fixed calling properties on non-objects
5+
16
# v0.15.1
27
* Bug fixes
38
* Fixed View module so that an element can have multiple elements within

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule ElixirScript.Mixfile do
44
def project do
55
[
66
app: :elixir_script,
7-
version: "0.15.1",
7+
version: "0.15.2-dev",
88
elixir: "~> 1.0",
99
escript: escript_config,
1010
deps: deps,

priv/Elixir.js

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/javascript/lib/core/functions.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ import Protocol from './protocol';
66
function call_property(item, property){
77
let prop = null;
88

9-
if(property in item){
9+
if(typeof item === "number" || typeof item === "symbol" || typeof item === "boolean" || typeof item === "string"){
10+
if(item[property] !== undefined){
1011
prop = property;
11-
}else if(Symbol.for(property) in item){
12-
prop = Symbol.for(property);
13-
}else{
14-
throw new Error(`Property ${property} not found in ${item}`);
12+
}else if(item[Symbol.for(property)] !== undefined){
13+
prop = Symbol.for(property);
14+
}
15+
} else {
16+
if(property in item){
17+
prop = property;
18+
}else if(Symbol.for(property) in item){
19+
prop = Symbol.for(property);
20+
}
21+
}
22+
23+
if(prop === null){
24+
throw new Error(`Property ${ property } not found in ${ item }`);
1525
}
1626

1727
if(item[prop] instanceof Function){

src/javascript/lib/core/protocol.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class Protocol{
4545
}
4646

4747
hasImplementation(thing) {
48+
if (thing === Integer || thing === Float){
49+
return this.registry.has(thing);
50+
}
51+
4852
return this.registry.has(thing.constructor);
4953
}
5054
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Functions = require('../../lib/core').Functions;
2+
var expect = require('chai').expect;
3+
4+
describe('Functions', function(){
5+
6+
it('call_property', function(){
7+
expect(Functions.call_property(1, "toString")).to.equal("1");
8+
expect(Functions.call_property([], "toString")).to.equal("");
9+
expect(Functions.call_property([], "length")).to.equal(0);
10+
expect(Functions.call_property("", "toString")).to.equal("");
11+
expect(Functions.call_property("", "length")).to.equal(0);
12+
expect(Functions.call_property(Symbol("test"), "toString")).to.equal("Symbol(test)");
13+
expect(Functions.call_property({completed: false}, "completed")).to.equal(false);
14+
expect(Functions.call_property({id: 0}, "id")).to.equal(0);
15+
});
16+
17+
});

0 commit comments

Comments
 (0)