spoint 0.1.0 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -209
- package/SKILL.md +95 -0
- package/apps/environment/index.js +200 -1
- package/apps/environment/models/decorative/.gitkeep +0 -0
- package/apps/environment/models/hazards/.gitkeep +0 -0
- package/apps/environment/models/interactive/.gitkeep +0 -0
- package/apps/environment/models/structures/.gitkeep +0 -0
- package/apps/environment/smartObjects.js +114 -0
- package/apps/interactable/index.js +155 -0
- package/apps/physics-crate/index.js +15 -9
- package/apps/power-crate/index.js +18 -12
- package/apps/tps-game/$GDUPI.vrm +0 -0
- package/apps/tps-game/Cleetus.vrm +0 -0
- package/apps/tps-game/index.js +185 -27
- package/apps/world/index.js +68 -22
- package/bin/create-app.js +337 -0
- package/client/ARControls.js +301 -0
- package/client/LoadingManager.js +117 -0
- package/client/MobileControls.js +1122 -0
- package/client/anim-lib.glb +0 -0
- package/client/animation.js +306 -0
- package/client/app.js +1341 -65
- package/client/camera.js +191 -33
- package/client/createLoadingScreen.js +69 -0
- package/client/editor/bridge.js +113 -0
- package/client/editor/css/main.css +794 -0
- package/client/editor/images/rotate.svg +4 -0
- package/client/editor/images/scale.svg +4 -0
- package/client/editor/images/translate.svg +4 -0
- package/client/editor/index.html +103 -0
- package/client/editor/js/Command.js +41 -0
- package/client/editor/js/Config.js +81 -0
- package/client/editor/js/Editor.js +785 -0
- package/client/editor/js/EditorControls.js +438 -0
- package/client/editor/js/History.js +321 -0
- package/client/editor/js/Loader.js +987 -0
- package/client/editor/js/LoaderUtils.js +90 -0
- package/client/editor/js/Menubar.Add.js +510 -0
- package/client/editor/js/Menubar.Edit.js +145 -0
- package/client/editor/js/Menubar.File.js +466 -0
- package/client/editor/js/Menubar.Help.js +73 -0
- package/client/editor/js/Menubar.Status.js +51 -0
- package/client/editor/js/Menubar.View.js +183 -0
- package/client/editor/js/Menubar.js +27 -0
- package/client/editor/js/Player.js +53 -0
- package/client/editor/js/Resizer.js +58 -0
- package/client/editor/js/Script.js +503 -0
- package/client/editor/js/Selector.js +102 -0
- package/client/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.BufferGeometry.js +115 -0
- package/client/editor/js/Sidebar.Geometry.CapsuleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
- package/client/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
- package/client/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
- package/client/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
- package/client/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
- package/client/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
- package/client/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
- package/client/editor/js/Sidebar.Geometry.js +332 -0
- package/client/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.ColorProperty.js +87 -0
- package/client/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
- package/client/editor/js/Sidebar.Material.MapProperty.js +249 -0
- package/client/editor/js/Sidebar.Material.NumberProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.Program.js +73 -0
- package/client/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
- package/client/editor/js/Sidebar.Material.js +751 -0
- package/client/editor/js/Sidebar.Object.Animation.js +102 -0
- package/client/editor/js/Sidebar.Object.js +898 -0
- package/client/editor/js/Sidebar.Project.App.js +165 -0
- package/client/editor/js/Sidebar.Project.Image.js +225 -0
- package/client/editor/js/Sidebar.Project.Materials.js +82 -0
- package/client/editor/js/Sidebar.Project.Renderer.js +144 -0
- package/client/editor/js/Sidebar.Project.Video.js +242 -0
- package/client/editor/js/Sidebar.Project.js +31 -0
- package/client/editor/js/Sidebar.Properties.js +73 -0
- package/client/editor/js/Sidebar.Scene.js +585 -0
- package/client/editor/js/Sidebar.Script.js +129 -0
- package/client/editor/js/Sidebar.Settings.History.js +146 -0
- package/client/editor/js/Sidebar.Settings.Shortcuts.js +175 -0
- package/client/editor/js/Sidebar.Settings.js +60 -0
- package/client/editor/js/Sidebar.js +41 -0
- package/client/editor/js/Storage.js +98 -0
- package/client/editor/js/Strings.js +2028 -0
- package/client/editor/js/Toolbar.js +84 -0
- package/client/editor/js/Viewport.Controls.js +92 -0
- package/client/editor/js/Viewport.Info.js +136 -0
- package/client/editor/js/Viewport.Pathtracer.js +91 -0
- package/client/editor/js/Viewport.ViewHelper.js +39 -0
- package/client/editor/js/Viewport.XR.js +222 -0
- package/client/editor/js/Viewport.js +900 -0
- package/client/editor/js/commands/AddObjectCommand.js +68 -0
- package/client/editor/js/commands/AddScriptCommand.js +75 -0
- package/client/editor/js/commands/Commands.js +23 -0
- package/client/editor/js/commands/MoveObjectCommand.js +111 -0
- package/client/editor/js/commands/MultiCmdsCommand.js +85 -0
- package/client/editor/js/commands/RemoveObjectCommand.js +88 -0
- package/client/editor/js/commands/RemoveScriptCommand.js +81 -0
- package/client/editor/js/commands/SetColorCommand.js +73 -0
- package/client/editor/js/commands/SetGeometryCommand.js +87 -0
- package/client/editor/js/commands/SetGeometryValueCommand.js +70 -0
- package/client/editor/js/commands/SetMaterialColorCommand.js +86 -0
- package/client/editor/js/commands/SetMaterialCommand.js +79 -0
- package/client/editor/js/commands/SetMaterialMapCommand.js +143 -0
- package/client/editor/js/commands/SetMaterialRangeCommand.js +91 -0
- package/client/editor/js/commands/SetMaterialValueCommand.js +90 -0
- package/client/editor/js/commands/SetMaterialVectorCommand.js +79 -0
- package/client/editor/js/commands/SetPositionCommand.js +84 -0
- package/client/editor/js/commands/SetRotationCommand.js +84 -0
- package/client/editor/js/commands/SetScaleCommand.js +84 -0
- package/client/editor/js/commands/SetSceneCommand.js +103 -0
- package/client/editor/js/commands/SetScriptValueCommand.js +80 -0
- package/client/editor/js/commands/SetShadowValueCommand.js +73 -0
- package/client/editor/js/commands/SetUuidCommand.js +70 -0
- package/client/editor/js/commands/SetValueCommand.js +75 -0
- package/client/editor/js/libs/acorn/acorn.js +3236 -0
- package/client/editor/js/libs/acorn/acorn_loose.js +1299 -0
- package/client/editor/js/libs/acorn/walk.js +344 -0
- package/client/editor/js/libs/app/index.html +57 -0
- package/client/editor/js/libs/app.js +251 -0
- package/client/editor/js/libs/codemirror/addon/dialog.css +32 -0
- package/client/editor/js/libs/codemirror/addon/dialog.js +163 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.css +36 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.js +529 -0
- package/client/editor/js/libs/codemirror/addon/tern.css +87 -0
- package/client/editor/js/libs/codemirror/addon/tern.js +750 -0
- package/client/editor/js/libs/codemirror/codemirror.css +344 -0
- package/client/editor/js/libs/codemirror/codemirror.js +9849 -0
- package/client/editor/js/libs/codemirror/mode/glsl.js +233 -0
- package/client/editor/js/libs/codemirror/mode/javascript.js +959 -0
- package/client/editor/js/libs/codemirror/theme/monokai.css +41 -0
- package/client/editor/js/libs/esprima.js +6401 -0
- package/client/editor/js/libs/jsonlint.js +453 -0
- package/client/editor/js/libs/signals.min.js +14 -0
- package/client/editor/js/libs/tern-threejs/threejs.js +5031 -0
- package/client/editor/js/libs/ternjs/comment.js +87 -0
- package/client/editor/js/libs/ternjs/def.js +588 -0
- package/client/editor/js/libs/ternjs/doc_comment.js +401 -0
- package/client/editor/js/libs/ternjs/infer.js +1635 -0
- package/client/editor/js/libs/ternjs/polyfill.js +80 -0
- package/client/editor/js/libs/ternjs/signal.js +26 -0
- package/client/editor/js/libs/ternjs/tern.js +993 -0
- package/client/editor/js/libs/ui.js +1346 -0
- package/client/editor/js/libs/ui.three.js +855 -0
- package/client/facial-animation.js +455 -0
- package/client/index.html +7 -4
- package/client/loading.css +147 -0
- package/client/loading.html +25 -0
- package/client/style.css +251 -0
- package/package.json +7 -3
- package/server.js +9 -1
- package/src/apps/AppContext.js +1 -1
- package/src/apps/AppLoader.js +50 -37
- package/src/apps/AppRuntime.js +32 -8
- package/src/client/InputHandler.js +233 -0
- package/src/client/JitterBuffer.js +207 -0
- package/src/client/KalmanFilter.js +125 -0
- package/src/client/MessageHandler.js +101 -0
- package/src/client/PhysicsNetworkClient.js +141 -68
- package/src/client/ReconnectManager.js +62 -0
- package/src/client/SmoothInterpolation.js +127 -0
- package/src/client/SnapshotProcessor.js +144 -0
- package/src/connection/ConnectionManager.js +21 -3
- package/src/connection/SessionStore.js +13 -3
- package/src/index.client.js +4 -6
- package/src/netcode/EventLog.js +29 -15
- package/src/netcode/LagCompensator.js +25 -26
- package/src/netcode/NetworkState.js +4 -1
- package/src/netcode/PhysicsIntegration.js +20 -6
- package/src/netcode/PlayerManager.js +10 -2
- package/src/netcode/SnapshotEncoder.js +66 -19
- package/src/netcode/TickSystem.js +13 -4
- package/src/physics/World.js +66 -13
- package/src/protocol/msgpack.js +90 -63
- package/src/sdk/ReloadHandlers.js +12 -2
- package/src/sdk/ReloadManager.js +5 -0
- package/src/sdk/ServerHandlers.js +50 -11
- package/src/sdk/StaticHandler.js +22 -6
- package/src/sdk/TickHandler.js +101 -34
- package/src/sdk/scaffold.js +28 -0
- package/src/sdk/server.js +59 -33
- package/src/shared/movement.js +2 -1
- package/src/spatial/Octree.js +5 -0
- package/apps/interactive-door/index.js +0 -33
- package/apps/patrol-npc/index.js +0 -37
- package/src/connection/QualityMonitor.js +0 -46
- package/src/debug/StateInspector.js +0 -42
- package/src/index.js +0 -1
- package/src/index.server.js +0 -27
- package/src/protocol/Codec.js +0 -60
- package/src/protocol/SequenceTracker.js +0 -71
- package/src/sdk/ClientMessageHandler.js +0 -80
- package/src/sdk/client.js +0 -122
- package/world/kaira.glb +0 -0
- package/world/schwust.glb +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
(function(mod) {
|
|
2
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
3
|
+
return mod(exports);
|
|
4
|
+
if (typeof define == "function" && define.amd) // AMD
|
|
5
|
+
return define(["exports"], mod);
|
|
6
|
+
mod(tern.comment || (tern.comment = {}));
|
|
7
|
+
})(function(exports) {
|
|
8
|
+
function isSpace(ch) {
|
|
9
|
+
return (ch < 14 && ch > 8) || ch === 32 || ch === 160;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function onOwnLine(text, pos) {
|
|
13
|
+
for (; pos > 0; --pos) {
|
|
14
|
+
var ch = text.charCodeAt(pos - 1);
|
|
15
|
+
if (ch == 10) break;
|
|
16
|
+
if (!isSpace(ch)) return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Gather comments directly before a function
|
|
22
|
+
exports.commentsBefore = function(text, pos) {
|
|
23
|
+
var found = null, emptyLines = 0, topIsLineComment;
|
|
24
|
+
out: while (pos > 0) {
|
|
25
|
+
var prev = text.charCodeAt(pos - 1);
|
|
26
|
+
if (prev == 10) {
|
|
27
|
+
for (var scan = --pos, sawNonWS = false; scan > 0; --scan) {
|
|
28
|
+
prev = text.charCodeAt(scan - 1);
|
|
29
|
+
if (prev == 47 && text.charCodeAt(scan - 2) == 47) {
|
|
30
|
+
if (!onOwnLine(text, scan - 2)) break out;
|
|
31
|
+
var content = text.slice(scan, pos);
|
|
32
|
+
if (!emptyLines && topIsLineComment) found[0] = content + "\n" + found[0];
|
|
33
|
+
else (found || (found = [])).unshift(content);
|
|
34
|
+
topIsLineComment = true;
|
|
35
|
+
emptyLines = 0;
|
|
36
|
+
pos = scan - 2;
|
|
37
|
+
break;
|
|
38
|
+
} else if (prev == 10) {
|
|
39
|
+
if (!sawNonWS && ++emptyLines > 1) break out;
|
|
40
|
+
break;
|
|
41
|
+
} else if (!sawNonWS && !isSpace(prev)) {
|
|
42
|
+
sawNonWS = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else if (prev == 47 && text.charCodeAt(pos - 2) == 42) {
|
|
46
|
+
for (var scan = pos - 2; scan > 1; --scan) {
|
|
47
|
+
if (text.charCodeAt(scan - 1) == 42 && text.charCodeAt(scan - 2) == 47) {
|
|
48
|
+
if (!onOwnLine(text, scan - 2)) break out;
|
|
49
|
+
(found || (found = [])).unshift(text.slice(scan, pos - 2));
|
|
50
|
+
topIsLineComment = false;
|
|
51
|
+
emptyLines = 0;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
pos = scan - 2;
|
|
56
|
+
} else if (isSpace(prev)) {
|
|
57
|
+
--pos;
|
|
58
|
+
} else {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return found;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.commentAfter = function(text, pos) {
|
|
66
|
+
while (pos < text.length) {
|
|
67
|
+
var next = text.charCodeAt(pos);
|
|
68
|
+
if (next == 47) {
|
|
69
|
+
var after = text.charCodeAt(pos + 1), end;
|
|
70
|
+
if (after == 47) // line comment
|
|
71
|
+
end = text.indexOf("\n", pos + 2);
|
|
72
|
+
else if (after == 42) // block comment
|
|
73
|
+
end = text.indexOf("*/", pos + 2);
|
|
74
|
+
else
|
|
75
|
+
return;
|
|
76
|
+
return text.slice(pos + 2, end < 0 ? text.length : end);
|
|
77
|
+
} else if (isSpace(next)) {
|
|
78
|
+
++pos;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.ensureCommentsBefore = function(text, node) {
|
|
84
|
+
if (node.hasOwnProperty("commentsBefore")) return node.commentsBefore;
|
|
85
|
+
return node.commentsBefore = exports.commentsBefore(text, node.start);
|
|
86
|
+
};
|
|
87
|
+
});
|
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
// Type description parser
|
|
2
|
+
//
|
|
3
|
+
// Type description JSON files (such as ecma5.json and browser.json)
|
|
4
|
+
// are used to
|
|
5
|
+
//
|
|
6
|
+
// A) describe types that come from native code
|
|
7
|
+
//
|
|
8
|
+
// B) to cheaply load the types for big libraries, or libraries that
|
|
9
|
+
// can't be inferred well
|
|
10
|
+
|
|
11
|
+
(function(mod) {
|
|
12
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
13
|
+
return exports.init = mod;
|
|
14
|
+
if (typeof define == "function" && define.amd) // AMD
|
|
15
|
+
return define({init: mod});
|
|
16
|
+
tern.def = {init: mod};
|
|
17
|
+
})(function(exports, infer) {
|
|
18
|
+
"use strict";
|
|
19
|
+
|
|
20
|
+
function hop(obj, prop) {
|
|
21
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var TypeParser = exports.TypeParser = function(spec, start, base, forceNew) {
|
|
25
|
+
this.pos = start || 0;
|
|
26
|
+
this.spec = spec;
|
|
27
|
+
this.base = base;
|
|
28
|
+
this.forceNew = forceNew;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function unwrapType(type, self, args) {
|
|
32
|
+
return type.call ? type(self, args) : type;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function extractProp(type, prop) {
|
|
36
|
+
if (prop == "!ret") {
|
|
37
|
+
if (type.retval) return type.retval;
|
|
38
|
+
var rv = new infer.AVal;
|
|
39
|
+
type.propagate(new infer.IsCallee(infer.ANull, [], null, rv));
|
|
40
|
+
return rv;
|
|
41
|
+
} else {
|
|
42
|
+
return type.getProp(prop);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function computedFunc(args, retType) {
|
|
47
|
+
return function(self, cArgs) {
|
|
48
|
+
var realArgs = [];
|
|
49
|
+
for (var i = 0; i < args.length; i++) realArgs.push(unwrapType(args[i], self, cArgs));
|
|
50
|
+
return new infer.Fn(name, infer.ANull, realArgs, unwrapType(retType, self, cArgs));
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function computedUnion(types) {
|
|
54
|
+
return function(self, args) {
|
|
55
|
+
var union = new infer.AVal;
|
|
56
|
+
for (var i = 0; i < types.length; i++) unwrapType(types[i], self, args).propagate(union);
|
|
57
|
+
return union;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function computedArray(inner) {
|
|
61
|
+
return function(self, args) {
|
|
62
|
+
return new infer.Arr(inner(self, args));
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
TypeParser.prototype = {
|
|
67
|
+
eat: function(str) {
|
|
68
|
+
if (str.length == 1 ? this.spec.charAt(this.pos) == str : this.spec.indexOf(str, this.pos) == this.pos) {
|
|
69
|
+
this.pos += str.length;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
word: function(re) {
|
|
74
|
+
var word = "", ch, re = re || /[\w$]/;
|
|
75
|
+
while ((ch = this.spec.charAt(this.pos)) && re.test(ch)) { word += ch; ++this.pos; }
|
|
76
|
+
return word;
|
|
77
|
+
},
|
|
78
|
+
error: function() {
|
|
79
|
+
throw new Error("Unrecognized type spec: " + this.spec + " (at " + this.pos + ")");
|
|
80
|
+
},
|
|
81
|
+
parseFnType: function(comp, name, top) {
|
|
82
|
+
var args = [], names = [], computed = false;
|
|
83
|
+
if (!this.eat(")")) for (var i = 0; ; ++i) {
|
|
84
|
+
var colon = this.spec.indexOf(": ", this.pos), argname;
|
|
85
|
+
if (colon != -1) {
|
|
86
|
+
argname = this.spec.slice(this.pos, colon);
|
|
87
|
+
if (/^[$\w?]+$/.test(argname))
|
|
88
|
+
this.pos = colon + 2;
|
|
89
|
+
else
|
|
90
|
+
argname = null;
|
|
91
|
+
}
|
|
92
|
+
names.push(argname);
|
|
93
|
+
var argType = this.parseType(comp);
|
|
94
|
+
if (argType.call) computed = true;
|
|
95
|
+
args.push(argType);
|
|
96
|
+
if (!this.eat(", ")) {
|
|
97
|
+
this.eat(")") || this.error();
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var retType, computeRet, computeRetStart, fn;
|
|
102
|
+
if (this.eat(" -> ")) {
|
|
103
|
+
var retStart = this.pos;
|
|
104
|
+
retType = this.parseType(true);
|
|
105
|
+
if (retType.call) {
|
|
106
|
+
if (top) {
|
|
107
|
+
computeRet = retType;
|
|
108
|
+
retType = infer.ANull;
|
|
109
|
+
computeRetStart = retStart;
|
|
110
|
+
} else {
|
|
111
|
+
computed = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
retType = infer.ANull;
|
|
116
|
+
}
|
|
117
|
+
if (computed) return computedFunc(args, retType);
|
|
118
|
+
|
|
119
|
+
if (top && (fn = this.base))
|
|
120
|
+
infer.Fn.call(this.base, name, infer.ANull, args, names, retType);
|
|
121
|
+
else
|
|
122
|
+
fn = new infer.Fn(name, infer.ANull, args, names, retType);
|
|
123
|
+
if (computeRet) fn.computeRet = computeRet;
|
|
124
|
+
if (computeRetStart != null) fn.computeRetSource = this.spec.slice(computeRetStart, this.pos);
|
|
125
|
+
return fn;
|
|
126
|
+
},
|
|
127
|
+
parseType: function(comp, name, top) {
|
|
128
|
+
var main = this.parseTypeMaybeProp(comp, name, top);
|
|
129
|
+
if (!this.eat("|")) return main;
|
|
130
|
+
var types = [main], computed = main.call;
|
|
131
|
+
for (;;) {
|
|
132
|
+
var next = this.parseTypeMaybeProp(comp, name, top);
|
|
133
|
+
types.push(next);
|
|
134
|
+
if (next.call) computed = true;
|
|
135
|
+
if (!this.eat("|")) break;
|
|
136
|
+
}
|
|
137
|
+
if (computed) return computedUnion(types);
|
|
138
|
+
var union = new infer.AVal;
|
|
139
|
+
for (var i = 0; i < types.length; i++) types[i].propagate(union);
|
|
140
|
+
return union;
|
|
141
|
+
},
|
|
142
|
+
parseTypeMaybeProp: function(comp, name, top) {
|
|
143
|
+
var result = this.parseTypeInner(comp, name, top);
|
|
144
|
+
while (comp && this.eat(".")) result = this.extendWithProp(result);
|
|
145
|
+
return result;
|
|
146
|
+
},
|
|
147
|
+
extendWithProp: function(base) {
|
|
148
|
+
var propName = this.word(/[\w<>$!]/) || this.error();
|
|
149
|
+
if (base.apply) return function(self, args) {
|
|
150
|
+
return extractProp(base(self, args), propName);
|
|
151
|
+
};
|
|
152
|
+
return extractProp(base, propName);
|
|
153
|
+
},
|
|
154
|
+
parseTypeInner: function(comp, name, top) {
|
|
155
|
+
if (this.eat("fn(")) {
|
|
156
|
+
return this.parseFnType(comp, name, top);
|
|
157
|
+
} else if (this.eat("[")) {
|
|
158
|
+
var inner = this.parseType(comp);
|
|
159
|
+
this.eat("]") || this.error();
|
|
160
|
+
if (inner.call) return computedArray(inner);
|
|
161
|
+
if (top && this.base) {
|
|
162
|
+
infer.Arr.call(this.base, inner);
|
|
163
|
+
return this.base;
|
|
164
|
+
}
|
|
165
|
+
return new infer.Arr(inner);
|
|
166
|
+
} else if (this.eat("+")) {
|
|
167
|
+
var path = this.word(/[\w$<>\.!]/);
|
|
168
|
+
var base = parsePath(path + ".prototype");
|
|
169
|
+
if (!(base instanceof infer.Obj)) base = parsePath(path);
|
|
170
|
+
if (!(base instanceof infer.Obj)) return base;
|
|
171
|
+
if (comp && this.eat("[")) return this.parsePoly(base);
|
|
172
|
+
if (top && this.forceNew) return new infer.Obj(base);
|
|
173
|
+
return infer.getInstance(base);
|
|
174
|
+
} else if (comp && this.eat("!")) {
|
|
175
|
+
var arg = this.word(/\d/);
|
|
176
|
+
if (arg) {
|
|
177
|
+
arg = Number(arg);
|
|
178
|
+
return function(_self, args) {return args[arg] || infer.ANull;};
|
|
179
|
+
} else if (this.eat("this")) {
|
|
180
|
+
return function(self) {return self;};
|
|
181
|
+
} else if (this.eat("custom:")) {
|
|
182
|
+
var fname = this.word(/[\w$]/);
|
|
183
|
+
return customFunctions[fname] || function() { return infer.ANull; };
|
|
184
|
+
} else {
|
|
185
|
+
return this.fromWord("!" + this.word(/[\w$<>\.!]/));
|
|
186
|
+
}
|
|
187
|
+
} else if (this.eat("?")) {
|
|
188
|
+
return infer.ANull;
|
|
189
|
+
} else {
|
|
190
|
+
return this.fromWord(this.word(/[\w$<>\.!`]/));
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
fromWord: function(spec) {
|
|
194
|
+
var cx = infer.cx();
|
|
195
|
+
switch (spec) {
|
|
196
|
+
case "number": return cx.num;
|
|
197
|
+
case "string": return cx.str;
|
|
198
|
+
case "bool": return cx.bool;
|
|
199
|
+
case "<top>": return cx.topScope;
|
|
200
|
+
}
|
|
201
|
+
if (cx.localDefs && spec in cx.localDefs) return cx.localDefs[spec];
|
|
202
|
+
return parsePath(spec);
|
|
203
|
+
},
|
|
204
|
+
parsePoly: function(base) {
|
|
205
|
+
var propName = "<i>", match;
|
|
206
|
+
if (match = this.spec.slice(this.pos).match(/^\s*(\w+)\s*=\s*/)) {
|
|
207
|
+
propName = match[1];
|
|
208
|
+
this.pos += match[0].length;
|
|
209
|
+
}
|
|
210
|
+
var value = this.parseType(true);
|
|
211
|
+
if (!this.eat("]")) this.error();
|
|
212
|
+
if (value.call) return function(self, args) {
|
|
213
|
+
var instance = infer.getInstance(base);
|
|
214
|
+
value(self, args).propagate(instance.defProp(propName));
|
|
215
|
+
return instance;
|
|
216
|
+
};
|
|
217
|
+
var instance = infer.getInstance(base);
|
|
218
|
+
value.propagate(instance.defProp(propName));
|
|
219
|
+
return instance;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
function parseType(spec, name, base, forceNew) {
|
|
224
|
+
var type = new TypeParser(spec, null, base, forceNew).parseType(false, name, true);
|
|
225
|
+
if (/^fn\(/.test(spec)) for (var i = 0; i < type.args.length; ++i) (function(i) {
|
|
226
|
+
var arg = type.args[i];
|
|
227
|
+
if (arg instanceof infer.Fn && arg.args && arg.args.length) addEffect(type, function(_self, fArgs) {
|
|
228
|
+
var fArg = fArgs[i];
|
|
229
|
+
if (fArg) fArg.propagate(new infer.IsCallee(infer.cx().topScope, arg.args, null, infer.ANull));
|
|
230
|
+
});
|
|
231
|
+
})(i);
|
|
232
|
+
return type;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function addEffect(fn, handler, replaceRet) {
|
|
236
|
+
var oldCmp = fn.computeRet, rv = fn.retval;
|
|
237
|
+
fn.computeRet = function(self, args, argNodes) {
|
|
238
|
+
var handled = handler(self, args, argNodes);
|
|
239
|
+
var old = oldCmp ? oldCmp(self, args, argNodes) : rv;
|
|
240
|
+
return replaceRet ? handled : old;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
var parseEffect = exports.parseEffect = function(effect, fn) {
|
|
245
|
+
var m;
|
|
246
|
+
if (effect.indexOf("propagate ") == 0) {
|
|
247
|
+
var p = new TypeParser(effect, 10);
|
|
248
|
+
var origin = p.parseType(true);
|
|
249
|
+
if (!p.eat(" ")) p.error();
|
|
250
|
+
var target = p.parseType(true);
|
|
251
|
+
addEffect(fn, function(self, args) {
|
|
252
|
+
unwrapType(origin, self, args).propagate(unwrapType(target, self, args));
|
|
253
|
+
});
|
|
254
|
+
} else if (effect.indexOf("call ") == 0) {
|
|
255
|
+
var andRet = effect.indexOf("and return ", 5) == 5;
|
|
256
|
+
var p = new TypeParser(effect, andRet ? 16 : 5);
|
|
257
|
+
var getCallee = p.parseType(true), getSelf = null, getArgs = [];
|
|
258
|
+
if (p.eat(" this=")) getSelf = p.parseType(true);
|
|
259
|
+
while (p.eat(" ")) getArgs.push(p.parseType(true));
|
|
260
|
+
addEffect(fn, function(self, args) {
|
|
261
|
+
var callee = unwrapType(getCallee, self, args);
|
|
262
|
+
var slf = getSelf ? unwrapType(getSelf, self, args) : infer.ANull, as = [];
|
|
263
|
+
for (var i = 0; i < getArgs.length; ++i) as.push(unwrapType(getArgs[i], self, args));
|
|
264
|
+
var result = andRet ? new infer.AVal : infer.ANull;
|
|
265
|
+
callee.propagate(new infer.IsCallee(slf, as, null, result));
|
|
266
|
+
return result;
|
|
267
|
+
}, andRet);
|
|
268
|
+
} else if (m = effect.match(/^custom (\S+)\s*(.*)/)) {
|
|
269
|
+
var customFunc = customFunctions[m[1]];
|
|
270
|
+
if (customFunc) addEffect(fn, m[2] ? customFunc(m[2]) : customFunc);
|
|
271
|
+
} else if (effect.indexOf("copy ") == 0) {
|
|
272
|
+
var p = new TypeParser(effect, 5);
|
|
273
|
+
var getFrom = p.parseType(true);
|
|
274
|
+
p.eat(" ");
|
|
275
|
+
var getTo = p.parseType(true);
|
|
276
|
+
addEffect(fn, function(self, args) {
|
|
277
|
+
var from = unwrapType(getFrom, self, args), to = unwrapType(getTo, self, args);
|
|
278
|
+
from.forAllProps(function(prop, val, local) {
|
|
279
|
+
if (local && prop != "<i>")
|
|
280
|
+
to.propagate(new infer.PropHasSubset(prop, val));
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
} else {
|
|
284
|
+
throw new Error("Unknown effect type: " + effect);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
var currentTopScope;
|
|
289
|
+
|
|
290
|
+
var parsePath = exports.parsePath = function(path, scope) {
|
|
291
|
+
var cx = infer.cx(), cached = cx.paths[path], origPath = path;
|
|
292
|
+
if (cached != null) return cached;
|
|
293
|
+
cx.paths[path] = infer.ANull;
|
|
294
|
+
|
|
295
|
+
var base = scope || currentTopScope || cx.topScope;
|
|
296
|
+
|
|
297
|
+
if (cx.localDefs) for (var name in cx.localDefs) {
|
|
298
|
+
if (path.indexOf(name) == 0) {
|
|
299
|
+
if (path == name) return cx.paths[path] = cx.localDefs[path];
|
|
300
|
+
if (path.charAt(name.length) == ".") {
|
|
301
|
+
base = cx.localDefs[name];
|
|
302
|
+
path = path.slice(name.length + 1);
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
var parts = path.split(".");
|
|
309
|
+
for (var i = 0; i < parts.length && base != infer.ANull; ++i) {
|
|
310
|
+
var prop = parts[i];
|
|
311
|
+
if (prop.charAt(0) == "!") {
|
|
312
|
+
if (prop == "!proto") {
|
|
313
|
+
base = (base instanceof infer.Obj && base.proto) || infer.ANull;
|
|
314
|
+
} else {
|
|
315
|
+
var fn = base.getFunctionType();
|
|
316
|
+
if (!fn) {
|
|
317
|
+
base = infer.ANull;
|
|
318
|
+
} else if (prop == "!ret") {
|
|
319
|
+
base = fn.retval && fn.retval.getType(false) || infer.ANull;
|
|
320
|
+
} else {
|
|
321
|
+
var arg = fn.args && fn.args[Number(prop.slice(1))];
|
|
322
|
+
base = (arg && arg.getType(false)) || infer.ANull;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
} else if (base instanceof infer.Obj) {
|
|
326
|
+
var propVal = (prop == "prototype" && base instanceof infer.Fn) ? base.getProp(prop) : base.props[prop];
|
|
327
|
+
if (!propVal || propVal.isEmpty())
|
|
328
|
+
base = infer.ANull;
|
|
329
|
+
else
|
|
330
|
+
base = propVal.types[0];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
// Uncomment this to get feedback on your poorly written .json files
|
|
334
|
+
// if (base == infer.ANull) console.error("bad path: " + origPath + " (" + cx.curOrigin + ")");
|
|
335
|
+
cx.paths[origPath] = base == infer.ANull ? null : base;
|
|
336
|
+
return base;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
function emptyObj(ctor) {
|
|
340
|
+
var empty = Object.create(ctor.prototype);
|
|
341
|
+
empty.props = Object.create(null);
|
|
342
|
+
empty.isShell = true;
|
|
343
|
+
return empty;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function isSimpleAnnotation(spec) {
|
|
347
|
+
if (!spec["!type"] || /^(fn\(|\[)/.test(spec["!type"])) return false;
|
|
348
|
+
for (var prop in spec)
|
|
349
|
+
if (prop != "!type" && prop != "!doc" && prop != "!url" && prop != "!span" && prop != "!data")
|
|
350
|
+
return false;
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function passOne(base, spec, path) {
|
|
355
|
+
if (!base) {
|
|
356
|
+
var tp = spec["!type"];
|
|
357
|
+
if (tp) {
|
|
358
|
+
if (/^fn\(/.test(tp)) base = emptyObj(infer.Fn);
|
|
359
|
+
else if (tp.charAt(0) == "[") base = emptyObj(infer.Arr);
|
|
360
|
+
else throw new Error("Invalid !type spec: " + tp);
|
|
361
|
+
} else if (spec["!stdProto"]) {
|
|
362
|
+
base = infer.cx().protos[spec["!stdProto"]];
|
|
363
|
+
} else {
|
|
364
|
+
base = emptyObj(infer.Obj);
|
|
365
|
+
}
|
|
366
|
+
base.name = path;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
for (var name in spec) if (hop(spec, name) && name.charCodeAt(0) != 33) {
|
|
370
|
+
var inner = spec[name];
|
|
371
|
+
if (typeof inner == "string" || isSimpleAnnotation(inner)) continue;
|
|
372
|
+
var prop = base.defProp(name);
|
|
373
|
+
passOne(prop.getObjType(), inner, path ? path + "." + name : name).propagate(prop);
|
|
374
|
+
}
|
|
375
|
+
return base;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function passTwo(base, spec, path) {
|
|
379
|
+
if (base.isShell) {
|
|
380
|
+
delete base.isShell;
|
|
381
|
+
var tp = spec["!type"];
|
|
382
|
+
if (tp) {
|
|
383
|
+
parseType(tp, path, base);
|
|
384
|
+
} else {
|
|
385
|
+
var proto = spec["!proto"] && parseType(spec["!proto"]);
|
|
386
|
+
infer.Obj.call(base, proto instanceof infer.Obj ? proto : true, path);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
var effects = spec["!effects"];
|
|
391
|
+
if (effects && base instanceof infer.Fn) for (var i = 0; i < effects.length; ++i)
|
|
392
|
+
parseEffect(effects[i], base);
|
|
393
|
+
copyInfo(spec, base);
|
|
394
|
+
|
|
395
|
+
for (var name in spec) if (hop(spec, name) && name.charCodeAt(0) != 33) {
|
|
396
|
+
var inner = spec[name], known = base.defProp(name), innerPath = path ? path + "." + name : name;
|
|
397
|
+
if (typeof inner == "string") {
|
|
398
|
+
if (known.isEmpty()) parseType(inner, innerPath).propagate(known);
|
|
399
|
+
} else {
|
|
400
|
+
if (!isSimpleAnnotation(inner))
|
|
401
|
+
passTwo(known.getObjType(), inner, innerPath);
|
|
402
|
+
else if (known.isEmpty())
|
|
403
|
+
parseType(inner["!type"], innerPath, null, true).propagate(known);
|
|
404
|
+
else
|
|
405
|
+
continue;
|
|
406
|
+
if (inner["!doc"]) known.doc = inner["!doc"];
|
|
407
|
+
if (inner["!url"]) known.url = inner["!url"];
|
|
408
|
+
if (inner["!span"]) known.span = inner["!span"];
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return base;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function copyInfo(spec, type) {
|
|
415
|
+
if (spec["!doc"]) type.doc = spec["!doc"];
|
|
416
|
+
if (spec["!url"]) type.url = spec["!url"];
|
|
417
|
+
if (spec["!span"]) type.span = spec["!span"];
|
|
418
|
+
if (spec["!data"]) type.metaData = spec["!data"];
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function runPasses(type, arg) {
|
|
422
|
+
var parent = infer.cx().parent, pass = parent && parent.passes && parent.passes[type];
|
|
423
|
+
if (pass) for (var i = 0; i < pass.length; i++) pass[i](arg);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function doLoadEnvironment(data, scope) {
|
|
427
|
+
var cx = infer.cx();
|
|
428
|
+
|
|
429
|
+
infer.addOrigin(cx.curOrigin = data["!name"] || "env#" + cx.origins.length);
|
|
430
|
+
cx.localDefs = cx.definitions[cx.curOrigin] = Object.create(null);
|
|
431
|
+
|
|
432
|
+
runPasses("preLoadDef", data);
|
|
433
|
+
|
|
434
|
+
passOne(scope, data);
|
|
435
|
+
|
|
436
|
+
var def = data["!define"];
|
|
437
|
+
if (def) {
|
|
438
|
+
for (var name in def) {
|
|
439
|
+
var spec = def[name];
|
|
440
|
+
cx.localDefs[name] = typeof spec == "string" ? parsePath(spec) : passOne(null, spec, name);
|
|
441
|
+
}
|
|
442
|
+
for (var name in def) {
|
|
443
|
+
var spec = def[name];
|
|
444
|
+
if (typeof spec != "string") passTwo(cx.localDefs[name], def[name], name);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
passTwo(scope, data);
|
|
449
|
+
|
|
450
|
+
runPasses("postLoadDef", data);
|
|
451
|
+
|
|
452
|
+
cx.curOrigin = cx.localDefs = null;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
exports.load = function(data, scope) {
|
|
456
|
+
if (!scope) scope = infer.cx().topScope;
|
|
457
|
+
var oldScope = currentTopScope;
|
|
458
|
+
currentTopScope = scope;
|
|
459
|
+
try {
|
|
460
|
+
doLoadEnvironment(data, scope);
|
|
461
|
+
} finally {
|
|
462
|
+
currentTopScope = oldScope;
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
exports.parse = function(data, origin, path) {
|
|
467
|
+
var cx = infer.cx();
|
|
468
|
+
if (origin) {
|
|
469
|
+
cx.origin = origin;
|
|
470
|
+
cx.localDefs = cx.definitions[origin];
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
try {
|
|
474
|
+
if (typeof data == "string")
|
|
475
|
+
return parseType(data, path);
|
|
476
|
+
else
|
|
477
|
+
return passTwo(passOne(null, data, path), data, path);
|
|
478
|
+
} finally {
|
|
479
|
+
if (origin) cx.origin = cx.localDefs = null;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// Used to register custom logic for more involved effect or type
|
|
484
|
+
// computation.
|
|
485
|
+
var customFunctions = Object.create(null);
|
|
486
|
+
infer.registerFunction = function(name, f) { customFunctions[name] = f; };
|
|
487
|
+
|
|
488
|
+
var IsCreated = infer.constraint("created, target, spec", {
|
|
489
|
+
addType: function(tp) {
|
|
490
|
+
if (tp instanceof infer.Obj && this.created++ < 5) {
|
|
491
|
+
var derived = new infer.Obj(tp), spec = this.spec;
|
|
492
|
+
if (spec instanceof infer.AVal) spec = spec.getObjType(false);
|
|
493
|
+
if (spec instanceof infer.Obj) for (var prop in spec.props) {
|
|
494
|
+
var cur = spec.props[prop].types[0];
|
|
495
|
+
var p = derived.defProp(prop);
|
|
496
|
+
if (cur && cur instanceof infer.Obj && cur.props.value) {
|
|
497
|
+
var vtp = cur.props.value.getType(false);
|
|
498
|
+
if (vtp) p.addType(vtp);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
this.target.addType(derived);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
infer.registerFunction("Object_create", function(_self, args, argNodes) {
|
|
507
|
+
if (argNodes && argNodes.length && argNodes[0].type == "Literal" && argNodes[0].value == null)
|
|
508
|
+
return new infer.Obj();
|
|
509
|
+
|
|
510
|
+
var result = new infer.AVal;
|
|
511
|
+
if (args[0]) args[0].propagate(new IsCreated(0, result, args[1]));
|
|
512
|
+
return result;
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
var PropSpec = infer.constraint("target", {
|
|
516
|
+
addType: function(tp) {
|
|
517
|
+
if (!(tp instanceof infer.Obj)) return;
|
|
518
|
+
if (tp.hasProp("value"))
|
|
519
|
+
tp.getProp("value").propagate(this.target);
|
|
520
|
+
else if (tp.hasProp("get"))
|
|
521
|
+
tp.getProp("get").propagate(new infer.IsCallee(infer.ANull, [], null, this.target));
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
infer.registerFunction("Object_defineProperty", function(_self, args, argNodes) {
|
|
526
|
+
if (argNodes && argNodes.length >= 3 && argNodes[1].type == "Literal" &&
|
|
527
|
+
typeof argNodes[1].value == "string") {
|
|
528
|
+
var obj = args[0], connect = new infer.AVal;
|
|
529
|
+
obj.propagate(new infer.PropHasSubset(argNodes[1].value, connect, argNodes[1]));
|
|
530
|
+
args[2].propagate(new PropSpec(connect));
|
|
531
|
+
}
|
|
532
|
+
return infer.ANull;
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
infer.registerFunction("Object_defineProperties", function(_self, args, argNodes) {
|
|
536
|
+
if (args.length >= 2) {
|
|
537
|
+
var obj = args[0];
|
|
538
|
+
args[1].forAllProps(function(prop, val, local) {
|
|
539
|
+
if (!local) return;
|
|
540
|
+
var connect = new infer.AVal;
|
|
541
|
+
obj.propagate(new infer.PropHasSubset(prop, connect, argNodes && argNodes[1]));
|
|
542
|
+
val.propagate(new PropSpec(connect));
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
return infer.ANull;
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
var IsBound = infer.constraint("self, args, target", {
|
|
549
|
+
addType: function(tp) {
|
|
550
|
+
if (!(tp instanceof infer.Fn)) return;
|
|
551
|
+
this.target.addType(new infer.Fn(tp.name, infer.ANull, tp.args.slice(this.args.length),
|
|
552
|
+
tp.argNames.slice(this.args.length), tp.retval));
|
|
553
|
+
this.self.propagate(tp.self);
|
|
554
|
+
for (var i = 0; i < Math.min(tp.args.length, this.args.length); ++i)
|
|
555
|
+
this.args[i].propagate(tp.args[i]);
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
infer.registerFunction("Function_bind", function(self, args) {
|
|
560
|
+
if (!args.length) return infer.ANull;
|
|
561
|
+
var result = new infer.AVal;
|
|
562
|
+
self.propagate(new IsBound(args[0], args.slice(1), result));
|
|
563
|
+
return result;
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
infer.registerFunction("Array_ctor", function(_self, args) {
|
|
567
|
+
var arr = new infer.Arr;
|
|
568
|
+
if (args.length != 1 || !args[0].hasType(infer.cx().num)) {
|
|
569
|
+
var content = arr.getProp("<i>");
|
|
570
|
+
for (var i = 0; i < args.length; ++i) args[i].propagate(content);
|
|
571
|
+
}
|
|
572
|
+
return arr;
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
infer.registerFunction("Promise_ctor", function(_self, args, argNodes) {
|
|
576
|
+
if (args.length < 1) return infer.ANull;
|
|
577
|
+
var self = new infer.Obj(infer.cx().definitions.ecma6["Promise.prototype"]);
|
|
578
|
+
var valProp = self.defProp("value", argNodes && argNodes[0]);
|
|
579
|
+
var valArg = new infer.AVal;
|
|
580
|
+
valArg.propagate(valProp);
|
|
581
|
+
var exec = new infer.Fn("execute", infer.ANull, [valArg], ["value"], infer.ANull);
|
|
582
|
+
var reject = infer.cx().definitions.ecma6.promiseReject;
|
|
583
|
+
args[0].propagate(new infer.IsCallee(infer.ANull, [exec, reject], null, infer.ANull));
|
|
584
|
+
return self;
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
return exports;
|
|
588
|
+
});
|