Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 62485fd

Browse files
committed
Add support for defineProperties
Issue angelozerr#377
1 parent e274685 commit 62485fd

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

defs/ecma5.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"!doc": "Defines a new property directly on an object, or modifies an existing property on an object, and returns the object. If you want to see how to use the Object.defineProperty method with a binary-flags-like syntax, see this article."
3535
},
3636
"defineProperties": {
37-
"!type": "fn(obj: ?, props: ?)",
37+
"!type": "fn(obj: ?, props: ?) -> !custom:Object_defineProperties",
3838
"!url": "https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty",
3939
"!doc": "Defines a new property directly on an object, or modifies an existing property on an object, and returns the object. If you want to see how to use the Object.defineProperty method with a binary-flags-like syntax, see this article."
4040
},

lib/def.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,19 @@
533533
return infer.ANull;
534534
});
535535

536+
infer.registerFunction("Object_defineProperties", function(_self, args, argNodes) {
537+
if (args.length >= 2) {
538+
var obj = args[0];
539+
args[1].forAllProps(function(prop, val, local) {
540+
if (!local) return;
541+
var connect = new infer.AVal;
542+
obj.propagate(new infer.PropHasSubset(prop, connect, argNodes && argNodes[1]));
543+
val.propagate(new PropSpec(connect));
544+
});
545+
}
546+
return infer.ANull;
547+
});
548+
536549
var IsBound = infer.constraint("self, args, target", {
537550
addType: function(tp) {
538551
if (!(tp instanceof infer.Fn)) return;

test/cases/defineProperty.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ o.prop1; //: string
1313
o.prop2; //: number
1414

1515
o.prop1; //doc: Docstring for prop1
16+
17+
var o2 = {};
18+
19+
Object.defineProperties(o2, {
20+
prop1: {get: function() { return 2; }},
21+
prop2: {value: true}
22+
});
23+
24+
o2.prop1; //: number
25+
o2.prop2; //: bool

0 commit comments

Comments
 (0)