mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 893434 - OdinMonkey: make accessing non-data properties a link-time validation error (r=bbouvier)
--HG-- extra : rebase_source : 5b827256536c16d9e2da15e9877efcf393e1a9ef
This commit is contained in:
parent
40e230f211
commit
0b189f5cdf
@ -35,6 +35,18 @@ LinkFail(JSContext *cx, const char *str)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetDataProperty(JSContext *cx, const Value &objVal, HandlePropertyName field, MutableHandleValue v)
|
||||
{
|
||||
if (!objVal.isObject())
|
||||
return LinkFail(cx, "accessing property of non-object");
|
||||
if (!objVal.toObject().isNative())
|
||||
return LinkFail(cx, "accessing property of non-host object");
|
||||
if (!HasDataProperty(cx, &objVal.toObject(), NameToId(field), v.address()))
|
||||
return LinkFail(cx, "object missing data property");
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
ValidateGlobalVariable(JSContext *cx, const AsmJSModule &module, AsmJSModule::Global &global,
|
||||
HandleValue importVal)
|
||||
@ -55,7 +67,7 @@ ValidateGlobalVariable(JSContext *cx, const AsmJSModule &module, AsmJSModule::Gl
|
||||
case AsmJSModule::Global::InitImport: {
|
||||
RootedPropertyName field(cx, global.varImportField());
|
||||
RootedValue v(cx);
|
||||
if (!GetProperty(cx, importVal, field, &v))
|
||||
if (!GetDataProperty(cx, importVal, field, &v))
|
||||
return false;
|
||||
|
||||
switch (global.varImportCoercion()) {
|
||||
@ -81,7 +93,7 @@ ValidateFFI(JSContext *cx, AsmJSModule::Global &global, HandleValue importVal,
|
||||
{
|
||||
RootedPropertyName field(cx, global.ffiField());
|
||||
RootedValue v(cx);
|
||||
if (!GetProperty(cx, importVal, field, &v))
|
||||
if (!GetDataProperty(cx, importVal, field, &v))
|
||||
return false;
|
||||
|
||||
if (!v.isObject() || !v.toObject().is<JSFunction>())
|
||||
@ -97,7 +109,7 @@ ValidateArrayView(JSContext *cx, AsmJSModule::Global &global, HandleValue global
|
||||
{
|
||||
RootedPropertyName field(cx, global.viewName());
|
||||
RootedValue v(cx);
|
||||
if (!GetProperty(cx, globalVal, field, &v))
|
||||
if (!GetDataProperty(cx, globalVal, field, &v))
|
||||
return false;
|
||||
|
||||
if (!IsTypedArrayConstructor(v, global.viewType()))
|
||||
@ -110,10 +122,10 @@ static bool
|
||||
ValidateMathBuiltin(JSContext *cx, AsmJSModule::Global &global, HandleValue globalVal)
|
||||
{
|
||||
RootedValue v(cx);
|
||||
if (!GetProperty(cx, globalVal, cx->names().Math, &v))
|
||||
if (!GetDataProperty(cx, globalVal, cx->names().Math, &v))
|
||||
return false;
|
||||
RootedPropertyName field(cx, global.mathName());
|
||||
if (!GetProperty(cx, v, field, &v))
|
||||
if (!GetDataProperty(cx, v, field, &v))
|
||||
return false;
|
||||
|
||||
Native native = NULL;
|
||||
@ -146,7 +158,7 @@ ValidateGlobalConstant(JSContext *cx, AsmJSModule::Global &global, HandleValue g
|
||||
{
|
||||
RootedPropertyName field(cx, global.constantName());
|
||||
RootedValue v(cx);
|
||||
if (!GetProperty(cx, globalVal, field, &v))
|
||||
if (!GetDataProperty(cx, globalVal, field, &v))
|
||||
return false;
|
||||
|
||||
if (!v.isNumber())
|
||||
|
@ -78,8 +78,15 @@ function assertAsmLinkFail(f)
|
||||
if (!isAsmJSCompilationAvailable())
|
||||
return;
|
||||
|
||||
assertEq(isAsmJSModule(f), true);
|
||||
|
||||
// Verify no error is thrown with warnings off
|
||||
f.apply(null, Array.slice(arguments, 1));
|
||||
var ret = f.apply(null, Array.slice(arguments, 1));
|
||||
|
||||
assertEq(isAsmJSFunction(ret), false);
|
||||
if (typeof ret === 'object')
|
||||
for (f of ret)
|
||||
assertEq(isAsmJSFunction(f), false);
|
||||
|
||||
// Turn on warnings-as-errors
|
||||
var oldOpts = options("werror");
|
||||
|
@ -43,13 +43,27 @@ assertEq(asmLink(code, {NaN:NaN})(), NaN);
|
||||
var code = asmCompile('global', USE_ASM + 'var i=global.NaN; function f() { return +i } return f');
|
||||
assertEq(asmLink(code, this)(), NaN);
|
||||
|
||||
assertAsmLinkFail(asmCompile('glob','foreign','buf', USE_ASM + 'var t = new glob.Int32Array(buf); function f() {} return f'), {get Int32Array(){return Int32Array}}, null, new ArrayBuffer(4096))
|
||||
assertAsmLinkFail(asmCompile('glob','foreign','buf', USE_ASM + 'var t = new glob.Int32Array(buf); function f() {} return f'), new Proxy({}, {get:function() {return Int32Array}}), null, new ArrayBuffer(4096))
|
||||
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var t = glob.Math.sin; function f() {} return f'), {get Math(){return Math}});
|
||||
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var t = glob.Math.sin; function f() {} return f'), new Proxy({}, {get:function(){return Math}}));
|
||||
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var t = glob.Math.sin; function f() {} return f'), {Math:{get sin(){return Math.sin}}});
|
||||
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var t = glob.Math.sin; function f() {} return f'), {Math:new Proxy({}, {get:function(){return Math.sin}})});
|
||||
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var t = glob.Infinity; function f() {} return f'), {get Infinity(){return Infinity}});
|
||||
assertAsmLinkFail(asmCompile('glob', USE_ASM + 'var t = glob.Math.sin; function f() {} return f'), new Proxy({}, {get:function(){return Infinity}}));
|
||||
assertAsmLinkFail(asmCompile('glob','foreign', USE_ASM + 'var i = foreign.x|0; function f() {} return f'), null, {get x(){return 42}})
|
||||
assertAsmLinkFail(asmCompile('glob','foreign', USE_ASM + 'var i = +foreign.x; function f() {} return f'), null, {get x(){return 42}})
|
||||
assertAsmLinkFail(asmCompile('glob','foreign', USE_ASM + 'var i = foreign.x|0; function f() {} return f'), null, new Proxy({}, {get:function() { return 42}}));
|
||||
assertAsmLinkFail(asmCompile('glob','foreign', USE_ASM + 'var i = +foreign.x; function f() {} return f'), null, new Proxy({}, {get:function() { return 42}}));
|
||||
assertAsmLinkFail(asmCompile('glob','foreign', USE_ASM + 'var i = foreign.x; function f() {} return f'), null, {get x(){return function(){}}})
|
||||
assertAsmLinkFail(asmCompile('glob','foreign', USE_ASM + 'var i = foreign.x; function f() {} return f'), null, new Proxy({}, {get:function() { return function(){}}}));
|
||||
assertAsmTypeFail('global', 'imp', USE_ASM + "var i=imp; function f() { return i|0 } return f");
|
||||
assertAsmTypeFail('global', 'imp', USE_ASM + "var j=0;var i=j.i|0; function f() { return i|0 } return f");
|
||||
assertAsmLinkAlwaysFail(asmCompile('global','imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f"), null, undefined);
|
||||
assertAsmLinkAlwaysFail(asmCompile('global','imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f"), this, undefined);
|
||||
assertAsmLinkAlwaysFail(asmCompile('global', 'imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f"), null, null);
|
||||
assertAsmLinkAlwaysFail(asmCompile('global', 'imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f"), this, null);
|
||||
assertEq(asmLink(asmCompile('global', 'imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f"), this, 42)(), 0);
|
||||
assertAsmLinkFail(asmCompile('global', 'imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f"), this, 42);
|
||||
assertEq(asmLink(asmCompile('global', 'imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f")(null, {i:42})), 42);
|
||||
assertEq(asmLink(asmCompile('global', 'imp', USE_ASM + "var i=imp.i|0; function f() { return i|0 } return f")(null, {i:1.4})), 1);
|
||||
assertEq(asmLink(asmCompile('global', 'imp', USE_ASM + "var i=+imp.i; function f() { return +i } return f")(null, {i:42})), 42);
|
||||
|
Loading…
Reference in New Issue
Block a user