Comparing version 0.0.4 to 0.0.5
@@ -22,4 +22,22 @@ var continuum = { | ||
}).apply(this, function(){ | ||
var exports = { builtins: {}, modules: {} }; | ||
var exports = { | ||
builtins: {}, | ||
modules: {}, | ||
fs: { | ||
readFile: function(path, encoding, callback){ | ||
var xhr = new XMLHttpRequest; | ||
xhr.responseType = 'text'; | ||
xhr.open('GET', path); | ||
xhr.onerror = xhr.onload = function(evt){ | ||
if (xhr.readyState === 4) { | ||
xhr.onload = xhr.onerror = null; | ||
callback(null, xhr.responseText); | ||
} | ||
} | ||
xhr.send(); | ||
} | ||
} | ||
}; | ||
function require(request){ | ||
@@ -26,0 +44,0 @@ request = request.slice(request.lastIndexOf('/') + 1); |
@@ -145,2 +145,24 @@ (function(global, continuum, constants, utility){ | ||
}, | ||
function batchAppend(subject){ | ||
if (!subject) return subject; | ||
if (!this.batcher) { | ||
var self = this, | ||
batcher = this.batcher = document.createDocumentFragment(); | ||
setTimeout(function(){ | ||
self.element.appendChild(self.batcher); | ||
self.batcher = null; | ||
self.onBatchAppend(batcher); | ||
}, 1); | ||
} | ||
if (subject.element) { | ||
this.children || (this.children = []); | ||
this.children.push(subject); | ||
this.batcher.appendChild(subject.element); | ||
} else if (subject instanceof Element) { | ||
this.batcher.appendChild(subject); | ||
} | ||
return subject; | ||
}, | ||
function onBatchAppend(){ | ||
}, | ||
function insert(subject, before){ | ||
@@ -1488,7 +1510,7 @@ if (!this.children) { | ||
this.addClass(op.name); | ||
this.append(new Span(op.name, 'op-name')); | ||
this.batchAppend(new Span(op.name, 'op-name')); | ||
if (op.name === 'GET' || op.name === 'PUT') { | ||
if (!isObject(item)) { | ||
var type = typeof item; | ||
this.append(new Span(translators[type](item), typeofs[type])); | ||
this.batchAppend(new Span(translators[type](item), typeofs[type])); | ||
} else { | ||
@@ -1502,3 +1524,3 @@ if (item.Reference) { | ||
if (base.NativeBrand) { | ||
if (!base.Proxy && base.NativeBrand) { | ||
item = base.properties.get(item.name); | ||
@@ -1509,10 +1531,10 @@ } | ||
if (item && item.NativeBrand) { | ||
var result = renderer.render(item); | ||
this.append(result); | ||
var result = render('normal', item); | ||
this.batchAppend(result); | ||
} | ||
} | ||
} else if (op.name === 'BINARY') { | ||
this.append(new Span(constants.BINARYOPS.getKey(instruction[0]), 'Operator')); | ||
this.batchAppend(new Span(constants.BINARYOPS.getKey(instruction[0]), 'Operator')); | ||
} else if (op.name === 'UNARY') { | ||
this.append(new Span(constants.UNARYOPS.getKey(instruction[0]), 'Operator')); | ||
this.batchAppend(new Span(constants.UNARYOPS.getKey(instruction[0]), 'Operator')); | ||
} else { | ||
@@ -1522,3 +1544,3 @@ for (var i=0; i < op.params; i++) { | ||
if (!isObject(param)) { | ||
this.append(new Span(param, typeofs[typeof param])); | ||
this.batchAppend(new Span(param, typeofs[typeof param])); | ||
} | ||
@@ -1538,2 +1560,5 @@ } | ||
inherit(Instructions, Component, [ | ||
function onBatchAppend(){ | ||
this.element.scrollTop = this.element.scrollHeight; | ||
}, | ||
function addInstruction(op){ | ||
@@ -1544,4 +1569,3 @@ // if (this.children.length > 100) { | ||
// } | ||
this.append(new Instruction(op[0], op[1])) | ||
this.element.scrollTop = this.element.scrollHeight; | ||
this.batchAppend(new Instruction(op[0], op[1])); | ||
} | ||
@@ -1571,21 +1595,39 @@ ]); | ||
var Property = (function(){ | ||
function Property(mirror, key){ | ||
function Property(mirror, name){ | ||
Component.call(this, 'li'); | ||
this.mirror = mirror; | ||
this.attrs = attributes[mirror.propAttributes(key)]; | ||
this.name = name; | ||
this.valueMirror = this.createValue(); | ||
this.value = render(this.valueRenderer, this.valueMirror); | ||
if (this.valueMirror.type === 'function' && this.valueMirror.getName() === name) { | ||
this.value.addClass(this.getAttributes()); | ||
} else { | ||
this.key = this.createKey(); | ||
} | ||
this.addClass('property'); | ||
this._key = key; | ||
this.key = new Key(key); | ||
this.key.addClass(this.attrs); | ||
this.append(this.key); | ||
this.prop = mirror.get(key); | ||
this.property = renderer.render(this.prop); | ||
this.append(this.property); | ||
this.append(_('div')); | ||
this.append(this.property.createTree()); | ||
this.append(this.value); | ||
this.initTree(); | ||
} | ||
inherit(Property, Component, [ | ||
inherit(Property, Component, { | ||
valueRenderer: 'normal' | ||
}, [ | ||
function getAttributes(){ | ||
return this.attrs = attributes[this.mirror.propAttributes(this.name)]; | ||
}, | ||
function createKey(){ | ||
var key = new Key(this.name); | ||
key.addClass(this.getAttributes()); | ||
return key; | ||
}, | ||
function createValue(){ | ||
return this.mirror.get(this.name); | ||
}, | ||
function initTree(){ | ||
this.append(_('div')); | ||
this.append(this.value.createTree()); | ||
}, | ||
function refresh(){ | ||
var attrs = attributes[this.mirror.propAttributes(this._key)]; | ||
var attrs = attributes[this.mirror.propAttributes(this.name)]; | ||
if (attrs !== this.attrs) { | ||
@@ -1596,9 +1638,10 @@ this.key.removeClass(this.attrs); | ||
} | ||
if (this.prop) { | ||
var prop = this.mirror.get(this._key); | ||
if (prop.subject !== this.prop.subject) { | ||
this.prop = prop; | ||
this.replace(this.property, renderer.render(prop)); | ||
} else if (this.property.tree) { | ||
this.property.tree.refresh(); | ||
if (this.valueMirror) { | ||
var valueMirror = this.createValue(); | ||
if (this.valueMirror !== valueMirror) { | ||
var element = this.value; | ||
this.valueMirror = valueMirror; | ||
this.value = render(this.valueRenderer, valueMirror); | ||
this.remove(element); | ||
this.append(this.value); | ||
} | ||
@@ -1612,53 +1655,15 @@ } | ||
function createSpecialProperty(label, classname, callback){ | ||
var SpecialProperty = function(mirror){ | ||
Component.call(this, 'li'); | ||
this.mirror = mirror; | ||
this.addClass('property'); | ||
this.key = new Key(label); | ||
this.key.addClass(classname); | ||
this.append(this.key); | ||
this.prop = callback(mirror); | ||
this.property = renderer.render(this.prop); | ||
this.append(this.property); | ||
this.append(_('div')); | ||
this.append(this.property.createTree()); | ||
var PreviewProperty = (function(){ | ||
function PreviewProperty(mirror, name){ | ||
Property.call(this, mirror, name); | ||
} | ||
inherit(SpecialProperty, Property, [ | ||
function refresh(){ | ||
var prop = callback(this.mirror); | ||
if (this.prop !== prop) { | ||
this.prop = prop; | ||
this.element.removeChild(this.element.lastElementChild); | ||
this.append(renderer.render(this.property)); | ||
} | ||
inherit(PreviewProperty, Property, { | ||
valueRenderer: 'subpreview' | ||
}, [ | ||
function initTree(){ | ||
return false; | ||
} | ||
]); | ||
return SpecialProperty; | ||
} | ||
var Scope = createSpecialProperty('[[scope]]', 'FunctionScope', function(mirror){ return mirror.getScope() }); | ||
var Proto = createSpecialProperty('[[proto]]', 'Proto', function(mirror){ return mirror.getPrototype() }); | ||
var Env = createSpecialProperty('[[env]]', 'Env', function(mirror){ return mirror.getEnvironment() }); | ||
var Outer = createSpecialProperty('[[outer]]', 'Outer', function(mirror){ return mirror.getPrototype() }); | ||
var PreviewProperty = (function(){ | ||
function PreviewProperty(mirror, key){ | ||
Component.call(this, 'li'); | ||
this.mirror = mirror; | ||
this.attrs = attributes[mirror.propAttributes(key)]; | ||
this.addClass('preview-property'); | ||
this.key = new Key(key); | ||
this.key.addClass(this.attrs); | ||
this.append(this.key); | ||
this.prop = mirror.get(key); | ||
this.property = previewRenderer.render(this.prop); | ||
this.append(this.property); | ||
} | ||
inherit(PreviewProperty, Property); | ||
return PreviewProperty; | ||
@@ -1670,20 +1675,18 @@ })(); | ||
function Index(mirror, index){ | ||
Component.call(this, 'li'); | ||
this.mirror = mirror; | ||
this._key = index; | ||
this.addClass('index'); | ||
this.prop = mirror.get(index); | ||
this.property = previewRenderer.render(this.prop); | ||
this.append(this.property); | ||
Property.call(this, mirror, index); | ||
} | ||
inherit(Index, PreviewProperty, [ | ||
function createKey(){ | ||
return null; | ||
}, | ||
function refresh(){ | ||
if (this.prop) { | ||
var prop = this.mirror.get(this._key); | ||
if (prop.subject !== this.prop.subject) { | ||
this.prop = prop; | ||
this.replace(this.property, renderer.render(prop)); | ||
} else if (this.property.tree) { | ||
this.property.tree.refresh(); | ||
if (this.valueMirror) { | ||
var valueMirror = this.mirror.get(this.name); | ||
if (this.valueMirror !== valueMirror) { | ||
var element = this.value; | ||
this.valueMirror = valueMirror; | ||
this.value = render(this.valueRenderer, valueMirror); | ||
this.remove(element); | ||
this.append(this.value); | ||
} | ||
@@ -1698,2 +1701,37 @@ } | ||
function createSpecialProperty(label, classname, method){ | ||
var SpecialProperty = function(mirror){ | ||
Property.call(this, mirror, label); | ||
} | ||
inherit(SpecialProperty, Property, [ | ||
function getAttributes(){ | ||
return this.attrs = classname; | ||
}, | ||
function createValue(){ | ||
return this.mirror[method](); | ||
}, | ||
function refresh(){ | ||
var valueMirror = this.createValue(); | ||
if (this.valueMirror !== valueMirror) { | ||
var element = this.value; | ||
this.valueMirror = valueMirror; | ||
this.value = render(this.valueRenderer, valueMirror); | ||
this.remove(element); | ||
this.append(this.value); | ||
} | ||
} | ||
]); | ||
return SpecialProperty; | ||
} | ||
var Scope = createSpecialProperty('[[scope]]', 'FunctionScope', 'getScope'); | ||
var Proto = createSpecialProperty('[[proto]]', 'Proto', 'getPrototype'); | ||
var Env = createSpecialProperty('[[env]]', 'Env', 'getEnvironment'); | ||
var Outer = createSpecialProperty('[[outer]]', 'Outer', 'getPrototype'); | ||
var Label = (function(){ | ||
@@ -1775,2 +1813,3 @@ function Label(kind){ | ||
this.tree = this.append(tree); | ||
this.tree.addClass('result-tree'); | ||
} | ||
@@ -1873,5 +1912,7 @@ } | ||
this.mirror = mirror; | ||
this.label = this.createLabel(); | ||
this.preview = this.createPreview(); | ||
this.addClass('branch'); | ||
this.label = this.append(this.createLabel()); | ||
this.preview = this.append(this.createPreview()); | ||
this.append(this.label); | ||
this.append(this.preview); | ||
} | ||
@@ -1894,3 +1935,6 @@ | ||
function createPreview(){ | ||
return previewRenderer.render(this.mirror); | ||
var preview = render('preview', this.mirror); | ||
var tree = new Div('.preview-tree'); | ||
tree.append(preview); | ||
return tree; | ||
}, | ||
@@ -1935,5 +1979,5 @@ function expand(){ | ||
utility.iterate(this.keys, function(key){ | ||
this.tree.append(new Property(this.mirror, key)); | ||
this.tree.batchAppend(new Property(this.mirror, key)); | ||
}, this); | ||
this.tree.append(new Proto(this.mirror)); | ||
this.tree.batchAppend(new Proto(this.mirror)); | ||
} | ||
@@ -1982,3 +2026,3 @@ return this; | ||
Branch.prototype.initTree.call(this); | ||
this.tree.append(new Scope(this.mirror)); | ||
this.tree.batchAppend(new Scope(this.mirror)); | ||
} | ||
@@ -2002,3 +2046,3 @@ ]); | ||
if (this.mirror.subject.env.outer) { | ||
this.tree.append(new Env(this.mirror)); | ||
this.tree.batchAppend(new Env(this.mirror)); | ||
} | ||
@@ -2024,6 +2068,6 @@ } | ||
utility.iterate(this.keys, function(key){ | ||
this.tree.append(new Property(this.mirror, key)); | ||
this.tree.batchAppend(new Property(this.mirror, key)); | ||
}, this); | ||
if (this.mirror.subject.outer) { | ||
this.tree.append(new Outer(this.mirror)); | ||
this.tree.batchAppend(new Outer(this.mirror)); | ||
} | ||
@@ -2092,3 +2136,3 @@ } | ||
utility.iterate(this.mirror.list(false), function(key){ | ||
this.append(new PreviewProperty(this.mirror, key)); | ||
this.batchAppend(new PreviewProperty(this.mirror, key)); | ||
}, this); | ||
@@ -2117,3 +2161,3 @@ }, | ||
for (var i=0; i < len; i++) { | ||
this.append(new Index(this.mirror, i)); | ||
this.batchAppend(new Index(this.mirror, i)); | ||
} | ||
@@ -2130,4 +2174,7 @@ } | ||
function FunctionPreview(mirror){ | ||
Preview.call(this, mirror); | ||
this.addClass('FunctionPreview'); | ||
Component.call(this, 'div'); | ||
this.mirror = mirror; | ||
this.addClass('preview'); | ||
this.addClass('Function'); | ||
this.createPreview(); | ||
} | ||
@@ -2146,64 +2193,97 @@ | ||
var renderer = continuum.createRenderer({ | ||
Unknown: Branch.create, | ||
BooleanValue: Leaf.create, | ||
StringValue: StringLeaf.create, | ||
NumberValue: NumberLeaf.create, | ||
UndefinedValue: Leaf.create, | ||
NullValue: Leaf.create, | ||
Accessor: Leaf.create, | ||
Global: GlobalBranch.create, | ||
Thrown: ThrownBranch.create, | ||
Arguments: Branch.create, | ||
Array: Branch.create, | ||
Boolean: Branch.create, | ||
Date: Branch.create, | ||
Error: Branch.create, | ||
Function: FunctionBranch.create, | ||
JSON: Branch.create, | ||
Map: Branch.create, | ||
Math: Branch.create, | ||
Module: Branch.create, | ||
Object: Branch.create, | ||
Number: Branch.create, | ||
RegExp: Branch.create, | ||
Scope: ScopeBranch.create, | ||
Set: Branch.create, | ||
String: Branch.create, | ||
WeakMap: Branch.create | ||
}); | ||
var render = (function(){ | ||
var renderers = { | ||
normal: continuum.createRenderer({ | ||
Accessor : Leaf.create, | ||
Arguments : Branch.create, | ||
Array : Branch.create, | ||
Boolean : Branch.create, | ||
BooleanValue : Leaf.create, | ||
Date : Branch.create, | ||
Error : Branch.create, | ||
Function : FunctionBranch.create, | ||
Global : GlobalBranch.create, | ||
JSON : Branch.create, | ||
Map : Branch.create, | ||
Math : Branch.create, | ||
Module : Branch.create, | ||
NullValue : Leaf.create, | ||
Number : Branch.create, | ||
NumberValue : NumberLeaf.create, | ||
Object : Branch.create, | ||
RegExp : Branch.create, | ||
Scope : ScopeBranch.create, | ||
Set : Branch.create, | ||
String : Branch.create, | ||
StringValue : StringLeaf.create, | ||
Thrown : ThrownBranch.create, | ||
UndefinedValue: Leaf.create, | ||
Unknown : Branch.create, | ||
WeakMap : Branch.create | ||
}), | ||
preview: continuum.createRenderer({ | ||
Accessor : Leaf.create, | ||
Arguments : Preview.create, | ||
Array : IndexedPreview.create, | ||
Boolean : Preview.create, | ||
BooleanValue : Leaf.create, | ||
Date : Preview.create, | ||
Error : Preview.create, | ||
Function : FunctionPreview.create, | ||
Global : Preview.create, | ||
JSON : Preview.create, | ||
Map : Preview.create, | ||
Math : Preview.create, | ||
Module : Preview.create, | ||
NullValue : Leaf.create, | ||
Number : Preview.create, | ||
NumberValue : NumberLeaf.create, | ||
Object : Preview.create, | ||
RegExp : Preview.create, | ||
Scope : Preview.create, | ||
Set : Preview.create, | ||
String : Preview.create, | ||
StringValue : StringLeaf.create, | ||
Thrown : Preview.create, | ||
UndefinedValue: Leaf.create, | ||
Unknown : Preview.create, | ||
WeakMap : Preview.create | ||
}), | ||
subpreview: continuum.createRenderer({ | ||
Accessor : Leaf.create, | ||
Arguments : Leaf.create, | ||
Array : Leaf.create, | ||
Boolean : Leaf.create, | ||
BooleanValue : Leaf.create, | ||
Date : Leaf.create, | ||
Error : Leaf.create, | ||
Function : FunctionPreview.create, | ||
Global : Leaf.create, | ||
JSON : Leaf.create, | ||
Map : Leaf.create, | ||
Math : Leaf.create, | ||
Module : Leaf.create, | ||
NullValue : Leaf.create, | ||
Number : Leaf.create, | ||
NumberValue : NumberLeaf.create, | ||
Object : Leaf.create, | ||
RegExp : Leaf.create, | ||
Scope : Leaf.create, | ||
Set : Leaf.create, | ||
String : Leaf.create, | ||
StringValue : StringLeaf.create, | ||
Thrown : Leaf.create, | ||
UndefinedValue: Leaf.create, | ||
Unknown : Leaf.create, | ||
WeakMap : Leaf.create | ||
}) | ||
}; | ||
var previewRenderer = continuum.createRenderer({ | ||
Unknown: Preview.create, | ||
BooleanValue: Leaf.create, | ||
StringValue: StringLeaf.create, | ||
NumberValue: NumberLeaf.create, | ||
UndefinedValue: Leaf.create, | ||
NullValue: Leaf.create, | ||
Accessor: Leaf.create, | ||
Global: Preview.create, | ||
Thrown: Preview.create, | ||
Arguments: Preview.create, | ||
Array: IndexedPreview.create, | ||
Boolean: Preview.create, | ||
Date: Preview.create, | ||
Error: Preview.create, | ||
Function: FunctionPreview.create, | ||
JSON: Preview.create, | ||
Map: Preview.create, | ||
Math: Preview.create, | ||
Module: Preview.create, | ||
Object: Preview.create, | ||
Number: Preview.create, | ||
RegExp: Preview.create, | ||
Scope: Preview.create, | ||
Set: Preview.create, | ||
String: Preview.create, | ||
WeakMap: Preview.create | ||
}); | ||
return function render(type, mirror){ | ||
return renderers[type].render(mirror); | ||
} | ||
})(); | ||
var win = new Component(window), | ||
@@ -2271,3 +2351,3 @@ body = new Component(document.body); | ||
realm = (function(){ | ||
function makeRealm(){ | ||
var realm = continuum.createRealm(); | ||
@@ -2280,3 +2360,3 @@ | ||
function inspect(o){ | ||
var tree = inspector.append(new Result(renderer.render(o))); | ||
var tree = inspector.append(new Result(render('normal', o))); | ||
inspector.element.scrollTop = inspector.element.scrollHeight; | ||
@@ -2332,3 +2412,8 @@ inspector.refresh(); | ||
return realm; | ||
})(); | ||
} | ||
setTimeout(function(){ | ||
realm = makeRealm(); | ||
}, 100); | ||
}(); | ||
@@ -2335,0 +2420,0 @@ |
@@ -709,14 +709,13 @@ var debug = (function(exports){ | ||
function MirrorProxy(subject){ | ||
this.subject = subject; | ||
if ('Call' in subject) { | ||
this.type = 'function'; | ||
var MirrorProxy = (function(){ | ||
function MirrorProxy(subject){ | ||
this.subject = subject; | ||
if ('Call' in subject) { | ||
this.type = 'function'; | ||
} | ||
this.attrs = create(null); | ||
this.props = create(null); | ||
this.kind = introspect(subject.Target).kind; | ||
} | ||
this.attrs = create(null); | ||
this.props = create(null); | ||
this.kind = introspect(subject.Target).kind; | ||
} | ||
void function(){ | ||
inherit(MirrorProxy, Mirror, { | ||
@@ -730,2 +729,10 @@ type: 'object' | ||
MirrorObject.prototype.getterAttrs, | ||
function getOwnDescriptor(key){ | ||
var desc = this.subject.GetOwnProperty(key); | ||
var out = {}; | ||
for (var k in desc) { | ||
out[k.toLowerCase()] = desc[k]; | ||
} | ||
return out; | ||
}, | ||
function label(){ | ||
@@ -735,48 +742,37 @@ return 'Proxy' + MirrorObject.prototype.label.call(this); | ||
function get(key){ | ||
this.refresh(key); | ||
return introspect(this.props.get(key)); | ||
return introspect(this.subject.Get(key)); | ||
}, | ||
function hasOwn(key){ | ||
return this.refresh(key); | ||
return this.subject.HasOwnProperty(key); | ||
}, | ||
function has(key){ | ||
return this.refresh(key) ? true : this.getPrototype().has(key); | ||
return this.subject.HasProperty(key); | ||
}, | ||
function isPropEnumerable(key){ | ||
if (this.refresh(key)) { | ||
return (this.attrs[key] & ENUMERABLE) > 0; | ||
} else { | ||
return false; | ||
} | ||
var desc = this.subject.GetOwnProperty(key); | ||
return !!(desc && desc.Enumerable); | ||
}, | ||
function isPropConfigurable(key){ | ||
if (this.refresh(key)) { | ||
return (this.attrs[key] & CONFIGURABLE) > 0; | ||
} else { | ||
return false; | ||
} | ||
var desc = this.subject.GetOwnProperty(key); | ||
return !!(desc && desc.Configurable); | ||
}, | ||
function isPropAccessor(key){ | ||
if (this.refresh(key)) { | ||
return (this.attrs[key] & ACCESSOR) > 0; | ||
} else { | ||
return false; | ||
} | ||
var desc = this.subject.GetOwnProperty(key); | ||
return !!(desc && desc.Get || desc.Set); | ||
}, | ||
function isPropWritable(key){ | ||
if (this.refresh(key)) { | ||
return !!(this.isAccessor() ? this.props[key].Set : this.attrs[key] & WRITABLE); | ||
} else { | ||
return false; | ||
} | ||
var desc = this.subject.GetOwnProperty(key); | ||
return !!(desc && desc.Writable); | ||
}, | ||
function propAttributes(key){ | ||
if (this.refresh(key)) { | ||
return this.attrs[key]; | ||
} else { | ||
return this.getPrototype().propAttributes(key); | ||
var desc = this.subject.GetOwnProperty(key); | ||
if (desc) { | ||
if ('Value' in desc) { | ||
return desc.Enumerable | (desc.Configurable << 1) | (desc.Writable << 2); | ||
} | ||
return desc.Enumerable | (desc.Configurable << 1) | A; | ||
} | ||
}, | ||
function ownAttrs(props){ | ||
var key, keys = this.subject.GetOwnPropertyNames(); | ||
var key, keys = this.subject.Enumerate(false, true); | ||
@@ -788,34 +784,14 @@ props || (props = create(null)); | ||
for (var i=0; i < keys.length; i++) { | ||
key = keys[i]; | ||
if (this.refresh(key)) { | ||
props[key] = this.attrs[key]; | ||
} | ||
props[keys[i]] = this.propAttributes(keys[i]); | ||
} | ||
return props; | ||
}, | ||
function refresh(key){ | ||
if (!(key in this.attrs)) { | ||
var desc = this.subject.GetOwnProperty(key, false); | ||
if (desc) { | ||
if ('Value' in desc) { | ||
this.attrs[key] = desc.Enumerable | (desc.Configurable << 1) | (desc.Writable << 2); | ||
this.props[key] = desc.Value; | ||
} else { | ||
this.attrs[key] = desc.Enumerable | (desc.Configurable << 1) | A; | ||
this.props[key] = { Get: desc.Get, Set: desc.Set }; | ||
} | ||
return true; | ||
} else { | ||
delete this.attrs[key]; | ||
delete this.props[key]; | ||
} | ||
} | ||
return false; | ||
} | ||
]); | ||
}(); | ||
return MirrorProxy; | ||
})(); | ||
var MirrorScope = (function(){ | ||
@@ -1046,3 +1022,3 @@ function MirrorScope(subject){ | ||
} else if (subject.NativeBrand) { | ||
if (subject.isProxy) { | ||
if (subject.Proxy) { | ||
return new MirrorProxy(subject); | ||
@@ -1049,0 +1025,0 @@ } else if ('Call' in subject) { |
@@ -127,2 +127,3 @@ var errors = (function(errors, messages, exports){ | ||
redefine_disallowed : ["Cannot redefine property: ", "$0"], | ||
apply_wrong_args : ["Invalid arguments used in apply"], | ||
define_disallowed : ["Cannot define property:", "$0", ", object is not extensible."], | ||
@@ -157,2 +158,3 @@ non_extensible_proto : ["$0", " is not extensible"], | ||
proxy_enumerate_properties : ["enumerate trap failed to include non-configurable enumerable property '", "$0", "'"], | ||
missing_fundamental_trap : ["Proxy handler is missing fundamental trap ", "$0"], | ||
non_object_superclass : ["non-object superclass provided"], | ||
@@ -159,0 +161,0 @@ non_object_superproto : ["non-object superprototype"], |
@@ -52,2 +52,5 @@ var operators = (function(exports){ | ||
if (HasPrimitiveBase(v)) { | ||
if (typeof base === STRING && v.name === 'length' || v.name >= 0 && v.name < base.length) { | ||
return base[v.name]; | ||
} | ||
base = new exports.$PrimitiveBase(base); | ||
@@ -54,0 +57,0 @@ } |
@@ -113,3 +113,3 @@ export function Array(...values){ | ||
iterator(){ | ||
return new ArrayIterator(this, 'key+value'); | ||
return new ArrayIterator(this, 'value'); | ||
}, | ||
@@ -116,0 +116,0 @@ join(separator){ |
@@ -41,8 +41,2 @@ export function log(...values){ | ||
$__setupFunction(log); | ||
$__setupFunction(dir); | ||
$__setupFunction(time); | ||
$__setupFunction(timeEnd); | ||
$__setupFunction(write); | ||
$__setupFunction(clear); | ||
$__setupFunction(backspace); | ||
$__setupFunctions(log, dir, time, timeEnd, write, clear, backspace); |
@@ -24,5 +24,3 @@ export function Function(...args){ | ||
$__setupFunction(apply); | ||
$__setupFunction(bind); | ||
$__setupFunction(call); | ||
$__setupFunctions(apply, bind, call); | ||
@@ -29,0 +27,0 @@ |
@@ -21,4 +21,3 @@ let decodeURI = $__decodeURI, | ||
$__setupFunction(isFinite); | ||
$__setupFunction(isNaN); | ||
$__setupFunctions(isFinite, isNaN); | ||
@@ -25,0 +24,0 @@ |
@@ -169,5 +169,20 @@ export function Object(value){ | ||
export function seal(object){ | ||
ensureObject(object, 'Object.seal'); | ||
var desc = { configurable: false }, | ||
props = $__Enumerate(object, false, false); | ||
for (var i=0; i < props.length; i++) { | ||
$__DefineOwnProperty(object, props[i], desc); | ||
} | ||
$__SetExtensible(object, false); | ||
return object; | ||
} | ||
$__defineMethods(Object, [assign, create, defineProperty, defineProperties, freeze, | ||
getOwnPropertyDescriptor, getOwnPropertyNames, getPropertyDescriptor, getPropertyNames, | ||
getPrototypeOf, isExtensible, isFrozen, isSealed, keys, preventExtensions]); | ||
getPrototypeOf, isExtensible, isFrozen, isSealed, keys, preventExtensions, seal]); | ||
@@ -195,5 +210,3 @@ | ||
$__setupFunction(isPrototypeOf); | ||
$__setupFunction(hasOwnProperty); | ||
$__setupFunction(propertyIsEnumerable); | ||
$__setupFunctions(isPrototypeOf, hasOwnProperty, propertyIsEnumerable); | ||
@@ -200,0 +213,0 @@ |
@@ -0,1 +1,19 @@ | ||
export function Proxy(target, handler){ | ||
ensureObject(target, 'Proxy'); | ||
ensureObject(handler, 'Proxy'); | ||
return $__ProxyCreate(target, handler); | ||
} | ||
function makeDefiner(desc){ | ||
return (object, key, value) => { | ||
desc.value = value; | ||
$__DefineOwnProperty(object, key, desc); | ||
desc.value = undefined; | ||
return object; | ||
}; | ||
} | ||
let ___ = 0b0000, | ||
@@ -14,67 +32,52 @@ E__ = 0b0001, | ||
function makeDefiner(desc){ | ||
return (object, key, value) => { | ||
desc.value = value; | ||
$__DefineOwnProperty(object, key, desc); | ||
desc.value = undefined; | ||
return object; | ||
}; | ||
} | ||
let defineNormal = makeDefiner({ writable: true, | ||
enumerable: true, | ||
configurable: true }); | ||
let sealer = { configurable: false }, | ||
freezer = { configurable: false, writable: false }; | ||
let defineNormal = makeDefiner(ECW); | ||
export class Handler { | ||
constructor(){} | ||
getOwnPropertyDescriptor(target, name){ | ||
ensureObject(target, 'Reflect.getOwnPropertyDescriptor'); | ||
name = $__ToPropertyName(name); | ||
return $__GetOwnProperty(target, name); | ||
throw $__Exception('missing_fundamental_trap', ['getOwnPropertyDescriptor']); | ||
} | ||
getOwnPropertyNames(target){ | ||
ensureObject(target, 'Reflect.getOwnPropertyNames'); | ||
return $__Enumerate(target, false, false); | ||
throw $__Exception('missing_fundamental_trap', ['getOwnPropertyNames']); | ||
} | ||
getPrototypeOf(target){ | ||
ensureObject(target, 'Reflect.getPrototypeOf'); | ||
return $__GetPrototype(target); | ||
throw $__Exception('missing_fundamental_trap', ['getPrototypeOf']); | ||
} | ||
defineProperty(target, name, desc){ | ||
ensureObject(target, 'Reflect.defineProperty'); | ||
ensureDescriptor(desc); | ||
name = $__ToPropertyName(name); | ||
$__DefineOwnProperty(target, name, desc); | ||
return object; | ||
throw $__Exception('missing_fundamental_trap', ['defineProperty']); | ||
} | ||
deleteProperty(target, name){ | ||
return $__Delete(target, name, false); | ||
throw $__Exception('missing_fundamental_trap', ['deleteProperty']); | ||
} | ||
preventExtensions(target){ | ||
ensureObject(target, 'Reflect.preventExtensions'); | ||
$__SetExtensible(target, false); | ||
return target; | ||
throw $__Exception('missing_fundamental_trap', ['preventExtensions']); | ||
} | ||
isExtensible(target){ | ||
ensureObject(target, 'Reflect.isExtensible'); | ||
return $__GetExtensible(target); | ||
throw $__Exception('missing_fundamental_trap', ['isExtensible']); | ||
} | ||
apply(target, thisArg, args){ | ||
return $__CallFunction(target, thisArg, args); | ||
throw $__Exception('missing_fundamental_trap', ['apply']); | ||
} | ||
seal(target) { | ||
var success = this.preventExtensions(target); | ||
success = !!success; | ||
if (success) { | ||
var props = this.getOwnPropertyNames(target); | ||
var l = +props.length; | ||
for (var i = 0; i < l; i++) { | ||
var name = props[i]; | ||
success = success && | ||
this.defineProperty(target, name, $__C); | ||
} | ||
if (!this.preventExtensions(target)) return false; | ||
var props = this.getOwnPropertyNames(target), | ||
len = +props.length; | ||
for (var i = 0; i < len; i++) { | ||
success = success && this.defineProperty(target, props[i], sealer); | ||
} | ||
@@ -85,19 +88,16 @@ return success; | ||
freeze(target){ | ||
var success = this.preventExtensions(target); | ||
if (success = !!success) { | ||
var props = this.getOwnPropertyNames(target), | ||
l = +props.length; | ||
if (!this.preventExtensions(target)) return false; | ||
for (var i = 0; i < l; i++) { | ||
var name = props[i], | ||
desc = this.getOwnPropertyDescriptor(target, name); | ||
var props = this.getOwnPropertyNames(target), | ||
len = +props.length; | ||
desc = normalizeAndCompletePropertyDescriptor(desc); | ||
if (isDataDescriptor(desc)) { | ||
success = success && this.defineProperty(target, name, $_CW); | ||
} else if (desc !== undefined) { | ||
success = success && this.defineProperty(target, name, $__C); | ||
} | ||
for (var i = 0; i < len; i++) { | ||
var name = props[i], | ||
desc = this.getOwnPropertyDescriptor(target, name); | ||
if (desc) { | ||
success = success && this.defineProperty(target, name, 'writable' in desc || 'value' in desc ? freezer : sealer); | ||
} | ||
} | ||
return success; | ||
@@ -108,10 +108,8 @@ } | ||
var props = this.getOwnPropertyNames(target), | ||
l = +props.length; | ||
len = +props.length; | ||
for (var i = 0; i < l; i++) { | ||
var name = props[i], | ||
desc = this.getOwnPropertyDescriptor(target, name); | ||
for (var i = 0; i < len; i++) { | ||
var desc = this.getOwnPropertyDescriptor(target, props[i]); | ||
desc = normalizeAndCompletePropertyDescriptor(desc); | ||
if (desc.configurable) { | ||
if (desc && desc.configurable) { | ||
return false; | ||
@@ -125,15 +123,8 @@ } | ||
var props = this.getOwnPropertyNames(target), | ||
l = +props.length; | ||
len = +props.length; | ||
for (var i = 0; i < l; i++) { | ||
var name = props[i], | ||
desc = this.getOwnPropertyDescriptor(target, name); | ||
for (var i = 0; i < len; i++) { | ||
var desc = this.getOwnPropertyDescriptor(target, props[i]); | ||
desc = normalizeAndCompletePropertyDescriptor(desc); | ||
if (isDataDescriptor(desc)) { | ||
if (desc.writable) { | ||
return false; | ||
} | ||
} | ||
if (desc.configurable) { | ||
if (desc.configurable || ('writable' in desc || 'value' in desc) && desc.writable) { | ||
return false; | ||
@@ -147,3 +138,2 @@ } | ||
var desc = this.getOwnPropertyDescriptor(target, name); | ||
desc = normalizeAndCompletePropertyDescriptor(desc); | ||
if (desc !== undefined) { | ||
@@ -153,11 +143,7 @@ return true; | ||
var proto = $__GetPrototype(target); | ||
if (proto === null) { | ||
return false; | ||
} | ||
return has(proto, name); | ||
return proto === null ? false : has(proto, name); | ||
} | ||
hasOwn(target,name){ | ||
var desc = this.getOwnPropertyDescriptor(target, name); | ||
return undefined !== normalizeAndCompletePropertyDescriptor(desc); | ||
hasOwn(target, name){ | ||
return this.getOwnPropertyDescriptor(target, name) !== undefined; | ||
} | ||
@@ -169,18 +155,11 @@ | ||
var desc = this.getOwnPropertyDescriptor(target, name); | ||
desc = normalizeAndCompletePropertyDescriptor(desc); | ||
if (desc === undefined) { | ||
var proto = $__GetPrototype(target); | ||
if (proto === null) { | ||
return undefined; | ||
} | ||
return get(proto, name, receiver); | ||
return proto === null ? undefined : this.get(proto, name, receiver); | ||
} | ||
if (isDataDescriptor(desc)) { | ||
if ('writable' in desc || 'value' in desc) { | ||
return desc.value; | ||
} | ||
var getter = desc.get; | ||
if (getter === undefined) { | ||
return undefined; | ||
} | ||
return $__CallFunction(desc.get, receiver, []); | ||
return getter === undefined ? undefined : $__CallFunction(getter, receiver, []); | ||
} | ||
@@ -190,6 +169,5 @@ | ||
var ownDesc = this.getOwnPropertyDescriptor(target, name); | ||
ownDesc = normalizeAndCompletePropertyDescriptor(ownDesc); | ||
if (ownDesc !== undefined) { | ||
if (isAccessorDescriptor(ownDesc)) { | ||
if ('get' in ownDesc || 'set' in ownDesc) { | ||
var setter = ownDesc.set; | ||
@@ -200,6 +178,7 @@ if (setter === undefined) return false; | ||
} | ||
if (ownDesc.writable === false) return false; | ||
if (receiver === target) { | ||
var updateDesc = { value: value }; | ||
$__DefineOwnProperty(receiver, name, updateDesc); | ||
if (ownDesc.writable === false) { | ||
return false; | ||
} else if (receiver === target) { | ||
$__DefineOwnProperty(receiver, name, { value: value }); | ||
return true; | ||
@@ -221,37 +200,32 @@ } else { | ||
return set(proto, name, value, receiver); | ||
return this.set(proto, name, value, receiver); | ||
} | ||
enumerate(target){ | ||
var trapResult = this.getOwnPropertyNames(target); | ||
var l = +trapResult.length; | ||
var result = []; | ||
for (var i = 0; i < l; i++) { | ||
var name = $__ToString(trapResult[i]); | ||
var desc = this.getOwnPropertyDescriptor(name); | ||
desc = normalizeAndCompletePropertyDescriptor(desc); | ||
if (desc !== undefined && desc.enumerable) { | ||
result.push(name); | ||
var result = this.getOwnPropertyNames(target), | ||
len = +result.length, | ||
out = []; | ||
for (var i = 0; i < len; i++) { | ||
var name = $__ToString(result[i]), | ||
desc = this.getOwnPropertyDescriptor(name); | ||
if (desc != null && !desc.enumerable) { | ||
out.push(name); | ||
} | ||
} | ||
var proto = $__GetPrototype(target); | ||
if (proto === null) { | ||
return result; | ||
} | ||
var inherited = enumerate(proto); | ||
// FIXME: filter duplicates | ||
return result.concat(inherited); | ||
return proto === null ? out : out.concat(enumerate(proto)); | ||
} | ||
iterate(target){ | ||
var trapResult = this.enumerate(target); | ||
var l = +trapResult.length; | ||
var idx = 0; | ||
var result = this.enumerate(target), | ||
len = +result.length, | ||
i = 0; | ||
return { | ||
next: function() { | ||
if (idx === l) { | ||
throw StopIteration; | ||
} else { | ||
return trapResult[idx++]; | ||
} | ||
next(){ | ||
if (i === len) throw StopIteration; | ||
return result[i++]; | ||
} | ||
@@ -262,10 +236,11 @@ }; | ||
keys(target){ | ||
var trapResult = this.getOwnPropertyNames(target); | ||
var l = +trapResult.length; | ||
var result = []; | ||
for (var i = 0; i < l; i++) { | ||
var name = $__ToString(trapResult[i]); | ||
var desc = this.getOwnPropertyDescriptor(name); | ||
desc = normalizeAndCompletePropertyDescriptor(desc); | ||
if (desc !== undefined && desc.enumerable) { | ||
var result = this.getOwnPropertyNames(target), | ||
len = +result.length, | ||
result = []; | ||
for (var i = 0; i < len; i++) { | ||
var name = $__ToString(result[i]), | ||
desc = this.getOwnPropertyDescriptor(name); | ||
if (desc != null && desc.enumerable) { | ||
result.push(name); | ||
@@ -278,14 +253,7 @@ } | ||
construct(target, args) { | ||
var proto = this.get(target, 'prototype', target); | ||
var instance; | ||
if (Object(proto) === proto) { | ||
instance = $__ObjectCreate(proto); | ||
} else { | ||
instance = {}; | ||
} | ||
var res = this.apply(target, instance, args); | ||
if (Object(res) === res) { | ||
return res; | ||
} | ||
return instance; | ||
var proto = this.get(target, 'prototype', target), | ||
instance = $__Type(proto) === 'Object' ? $__ObjectCreate(proto) : {}, | ||
result = this.apply(target, instance, args); | ||
return $__Type(result) === 'Object' ? result : instance; | ||
} | ||
@@ -295,52 +263,86 @@ } | ||
export function apply(target, thisArg, args){ | ||
ensureFunction(target, '@Reflect.apply'); | ||
return $__CallFunction(target, thisArg, ensureArgs(args)); | ||
} | ||
export function Proxy(target, handler){} | ||
export function construct(target, args){ | ||
ensureFunction(target, '@Reflect.construct'); | ||
return $__Construct(target, ensureArgs(args)); | ||
} | ||
export var { | ||
getOwnPropertyDescriptor, | ||
getOwnPropertyNames, | ||
getPrototypeOf, | ||
defineProperty, | ||
deleteProperty, | ||
preventExtensions, | ||
isExtensible, | ||
apply | ||
} = Handler.prototype; | ||
export function defineProperty(target, name, desc){ | ||
ensureObject(target, '@Reflect.defineProperty'); | ||
ensureDescriptor(desc); | ||
name = $__ToPropertyName(name); | ||
$__DefineOwnProperty(target, name, desc); | ||
return object; | ||
} | ||
export function deleteProperty(target, name){ | ||
ensureObject(target, '@Reflect.deleteProperty'); | ||
name = $__ToPropertyName(name); | ||
return $__Delete(target, name, false); | ||
} | ||
export function enumerate(target){ | ||
ensureObject(target, 'Reflect.enumerate'); | ||
return $__Enumerate(target, false, false); | ||
return $__Enumerate($__ToObject(target), false, false); | ||
} | ||
export function freeze(target){ | ||
ensureObject(target, 'Reflect.freeze'); | ||
if (Type(target) !== 'Object') return false; | ||
var success = $__SetExtensible(target, false); | ||
if (!success) return success; | ||
var props = $__Enumerate(target, false, false); | ||
len = props.length; | ||
for (var i=0; i < props.length; i++) { | ||
var desc = $__GetOwnProperty(target, props[i]); | ||
if (desc.configurable) { | ||
desc.configurable = false; | ||
if ('writable' in desc) { | ||
desc.writable = false; | ||
} | ||
$__DefineOwnProperty(target, props[i], desc); | ||
for (var i = 0; i < len; i++) { | ||
var desc = $__GetOwnProperty(target, props[i]), | ||
attrs = 'writable' in desc || 'value' in desc ? freezer : desc !== undefined ? sealer : null; | ||
if (attrs !== null) { | ||
success = success && $__DefineOwnProperty(target, props[i], attrs); | ||
} | ||
} | ||
return success; | ||
} | ||
$__SetExtensible(target, false); | ||
return target; | ||
export function get(target, name, receiver){ | ||
target = $__ToObject(target); | ||
name = $__ToPropertyName(name); | ||
receiver = receiver === undefined ? undefined : $__ToObject(receiver); | ||
return $__GetP(target, name, receiver); | ||
} | ||
export function seal(target){ | ||
export function getOwnPropertyDescriptor(target, name){ | ||
ensureObject(target, '@Reflect.getOwnPropertyDescriptor'); | ||
name = $__ToPropertyName(name); | ||
return $__GetOwnProperty(target, name); | ||
} | ||
export function getOwnPropertyNames(target){ | ||
ensureObject(target, '@Reflect.getOwnPropertyNames'); | ||
return $__Enumerate(target, false, false); | ||
} | ||
export function preventExtensions(target){ | ||
ensureObject(target, 'Reflect.preventExtensions'); | ||
$__SetExtensible(target, false); | ||
return target; | ||
export function getPrototypeOf(target){ | ||
ensureObject(target, '@Reflect.getPrototypeOf'); | ||
return $__GetPrototype(target); | ||
} | ||
export function has(target, name){ | ||
target = $__ToObject(target); | ||
name = $__ToPropertyName(name); | ||
return name in target; | ||
} | ||
export function hasOwn(target, name){ | ||
target = $__ToObject(target); | ||
name = $__ToPropertyName(name); | ||
return $__HasOwnProperty(target, name); | ||
} | ||
export function isFrozen(target){ | ||
ensureObject(target, 'Reflect.isFrozen'); | ||
ensureObject(target, '@Reflect.isFrozen'); | ||
if ($__GetExtensible(target)) { | ||
@@ -365,3 +367,3 @@ return false; | ||
export function isSealed(target){ | ||
ensureObject(target, 'Reflect.isSealed'); | ||
ensureObject(target, '@Reflect.isSealed'); | ||
if ($__GetExtensible(target)) { | ||
@@ -384,41 +386,72 @@ return false; | ||
export function isExtensible(target){ | ||
ensureObject(target, 'Reflect.isExtensible'); | ||
ensureObject(target, '@Reflect.isExtensible'); | ||
return $__GetExtensible(target); | ||
} | ||
export function has(target, name){ | ||
ensureObject(target, 'Reflect.has'); | ||
name = $__ToPropertyName(name); | ||
return $__HasProperty(target, name); | ||
export function keys(target){ | ||
ensureObject(target, '@Reflect.keys'); | ||
return $__Enumerate(target, false, true); | ||
} | ||
export function hasOwn(target, name){ | ||
ensureObject(target, 'Reflect.hasOwn'); | ||
name = $__ToPropertyName(name); | ||
return $__HasOwnProperty(target, name); | ||
export function preventExtensions(target){ | ||
if (Type(target) !== 'Object') return false; | ||
return $__SetExtensible(target, false); | ||
} | ||
export function keys(target){ | ||
ensureObject(target, 'Reflect.keys'); | ||
return $__Enumerate(target, false, true); | ||
} | ||
export function seal(target){ | ||
if (Type(target) !== 'Object') return false; | ||
var success = $__SetExtensible(target, false); | ||
if (!success) return success; | ||
export function get(target, name, receiver){ | ||
ensureObject(target, 'Reflect.get'); | ||
name = $__ToPropertyName(name); | ||
return $__GetP(target, name, receiver); | ||
var props = $__Enumerate(target, false, false); | ||
len = props.length; | ||
for (var i = 0; i < len; i++) { | ||
success = success && $__DefineOwnProperty(target, props[i], sealer); | ||
} | ||
return success; | ||
} | ||
export function set(target, name, value, receiver){ | ||
ensureObject(target, 'Reflect.set'); | ||
target = $__ToObject(target); | ||
name = $__ToPropertyName(name); | ||
receiver = receiver === undefined ? undefined : $__ToObject(receiver); | ||
return $__SetP(target, name, value, receiver); | ||
} | ||
export function apply(target, thisArg, args){ | ||
return $__CallFunction(target, thisArg, args); | ||
$__setupFunctions(getOwnPropertyDescriptor, getOwnPropertyNames, getPrototypeOf, | ||
defineProperty, deleteProperty, preventExtensions, isExtensible, apply, enumerate, | ||
freeze, seal, isFrozen, isSealed, has, hasOwn, keys, get, set, construct); | ||
function ensureObject(o, name){ | ||
var type = typeof o; | ||
if (type === 'object' ? o === null : type !== 'function') { | ||
throw $__Exception('called_on_non_object', [name]); | ||
} | ||
} | ||
export function construct(target, args){ | ||
return $__Construct(target, args); | ||
function ensureDescriptor(o){ | ||
if (o === null || typeof o !== 'object') { | ||
throw $__Exception('property_desc_object', [typeof o]) | ||
} | ||
} | ||
function ensureArgs(o, name){ | ||
if (o == null || typeof o !== 'object' || typeof $__getDirect(o, 'length') !== 'number') { | ||
throw $__Exception('apply_wrong_args', []); | ||
} | ||
var brand = $__GetNativeBrand(o); | ||
return brand === 'Array' || brand === 'Arguments' ? o : [...o]; | ||
} | ||
function ensureFunction(o, name){ | ||
if (typeof o !== 'function') { | ||
throw $__Exception('called_on_non_function', [name]); | ||
} | ||
} |
@@ -31,2 +31,3 @@ // standard constants | ||
import Object from '@Object'; | ||
import Proxy from '@reflect'; | ||
import RegExp from '@RegExp'; | ||
@@ -58,3 +59,3 @@ import Set from '@Set'; | ||
export Array, Boolean, Date, Function, Map, Number, Object, RegExp, Set, String, WeakMap, | ||
export Array, Boolean, Date, Function, Map, Number, Object, Proxy, RegExp, Set, String, WeakMap, | ||
Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, | ||
@@ -61,0 +62,0 @@ decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, eval, isFinite, isNaN, |
@@ -44,7 +44,7 @@ { | ||
$__setupFunction = function setupFunction(func, name){ | ||
$__SetInternal(func, 'Native', true); | ||
$__deleteDirect(func, 'prototype'); | ||
if (name) { | ||
$__defineDirect(func, 'name', name, ___); | ||
$__setupFunctions = function setupFunctions(...funcs){ | ||
var len = funcs.length; | ||
for (var i=0; i < len; i++) { | ||
$__SetInternal(funcs[i], 'Native', true); | ||
$__deleteDirect(funcs[i], 'prototype'); | ||
} | ||
@@ -197,2 +197,3 @@ }; | ||
constructor(parent, options){ | ||
options = options || {}; | ||
this.linkedTo = options.linkedTo || null; | ||
@@ -205,3 +206,3 @@ _(this).set({ | ||
global : options.global || $__global, | ||
baseURL : options.baseURL || parent ? parent.baseURL : '', | ||
baseURL : options.baseURL || (parent ? parent.baseURL : ''), | ||
modules : $__ObjectCreate(null) | ||
@@ -286,3 +287,4 @@ }); | ||
$__System = new Loader(null, { | ||
export let System = new Loader(null, { | ||
global: $__global, | ||
@@ -292,3 +294,5 @@ baseURL: '', | ||
fetch(relURL, baseURL, request, resolved) { | ||
$__Fetch(resolved, src => { | ||
var fetcher = resolved[0] === '@' ? $__Fetch : $__readFile; | ||
fetcher(resolved, src => { | ||
if (typeof src === 'string') { | ||
@@ -302,3 +306,3 @@ request.fulfill(src); | ||
resolve(relURL, baseURL){ | ||
return baseURL + relURL; | ||
return relURL[0] === '@' ? relURL : $__resolve(baseURL, relURL); | ||
}, | ||
@@ -310,2 +314,2 @@ translate(src, relURL, baseURL, resolved) { | ||
$__System = System; |
@@ -27,5 +27,2 @@ export function clearInterval(id){ | ||
$__setupFunction(clearInterval); | ||
$__setupFunction(clearTimeout); | ||
$__setupFunction(setInterval); | ||
$__setupFunction(setTimeout); | ||
$__setupFunctions(clearInterval, clearTimeout, setInterval, setTimeout); |
{ | ||
"name": "continuum", | ||
"author": "Brandon Benvie <http://bbenvie.com>", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A JavaScript (ES6) bytecode virtual machine written in JavaScript", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -105,3 +105,3 @@ # Continuum - A JavaScript Virtual Machine Built in JavaScript | ||
### Realm ### | ||
## Realm ## | ||
A Realm is the main thing you interact with. Each realm has a global object with a unique set of builtin globals. A realm is roughly equivelent to an iframe or a node vm context. | ||
@@ -112,3 +112,2 @@ | ||
Realms are also event emitters and emit events as hooks to implement some APIs, such as the console, as well as vm signals like uncaught exceptions, or debugger pauses. | ||
@@ -132,2 +131,11 @@ __VM Events__ | ||
## Renderer ## | ||
A renderer is a visitor used to introspect VM objects and values. | ||
## Assembler ## | ||
An assembler is used to convert AST into bytecode and static script information. | ||
## Script ## | ||
A script contains all the bits related to a given chunk of source. The given options, sourcecode string, AST, bytecode, and the thunk (lazily created upon first execution). Scripts don't contain realm-specific information, so they are portable between realms/globals and can be executed multiple times as needed. | ||
# TODO | ||
@@ -134,0 +142,0 @@ * Hook up module system to environment |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
7266665
344
159362
145
66