8148924: Inconsistent "this" context in JSAdapter adaptee function calls

Reviewed-by: jlaskey
This commit is contained in:
Hannes Wallnöfer 2016-10-28 16:52:20 +02:00
parent b82b0af8c2
commit 6a77385b4d
5 changed files with 67 additions and 2 deletions

View File

@ -365,7 +365,7 @@ public final class NativeJSAdapter extends ScriptObject {
Object obj;
if (func instanceof ScriptFunction) {
obj = ScriptRuntime.apply((ScriptFunction)func, adaptee);
obj = ScriptRuntime.apply((ScriptFunction)func, this);
} else {
obj = new NativeArray(0);
}
@ -544,7 +544,7 @@ public final class NativeJSAdapter extends ScriptObject {
private Object callAdaptee(final Object retValue, final String name, final Object... args) {
final Object func = adaptee.get(name);
if (func instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)func, adaptee, args);
return ScriptRuntime.apply((ScriptFunction)func, this, args);
}
return retValue;
}

View File

@ -30,6 +30,7 @@
var obj = new JSAdapter() {
__getIds__: function() {
Assert.assertTrue(this === obj);
print("__getIds__ called");
return [ "foo", "bar" ];
}

View File

@ -30,39 +30,81 @@
var obj = new JSAdapter() {
__get__: function(name) {
Assert.assertTrue(this === obj);
print("getter called for '" + name + "'"); return name;
},
__put__: function(name, value) {
Assert.assertTrue(this === obj);
print("setter called for '" + name + "' with " + value);
},
__call__: function(name, arg1, arg2) {
Assert.assertTrue(this === obj);
print("method '" + name + "' called with " + arg1 + ", " + arg2);
},
__new__: function(arg1, arg2) {
Assert.assertTrue(this === obj);
print("new with " + arg1 + ", " + arg2);
},
__getKeys__: function() {
Assert.assertTrue(this === obj);
print("__getKeys__ called");
return [ "foo", "bar" ];
},
__getValues__: function() {
Assert.assertTrue(this === obj);
print("__getValues__ called");
return [ "fooval", "barval" ];
},
__has__: function(name) {
Assert.assertTrue(this === obj);
print("__has__ called with '" + name + "'");
return name == "js";
},
__delete__: function(name) {
Assert.assertTrue(this === obj);
print("__delete__ called with '" + name + "'");
return true;
},
__preventExtensions__ : function() {
Assert.assertTrue(this === obj);
print("__preventExtensions__ called");
},
__freeze__ : function() {
Assert.assertTrue(this === obj);
print("__freeze__ called");
},
__isFrozen__ : function() {
Assert.assertTrue(this === obj);
print("__isFrozen__ called");
return false;
},
__seal__ : function() {
Assert.assertTrue(this === obj);
print("__seal__ called");
},
__isSealed__ : function() {
Assert.assertTrue(this === obj);
print("__isSealed__ called");
return false;
},
__isExtensible__ : function() {
Assert.assertTrue(this === obj);
print("__isExtensible__ called");
return true;
}
};
@ -103,3 +145,13 @@ print(delete obj.prop);
print(obj["js"]);
obj["js"] = "javascript";
print(obj["javascript"]);
// call __isExtensible__, __isSealed__, __isFrozen__
print(Object.isExtensible(obj));
print(Object.isSealed(obj));
print(Object.isFrozen(obj));
// call __freeze__, __seal__, __preventExtensions__
Object.freeze(obj);
Object.seal(obj);
Object.preventExtensions(obj);

View File

@ -20,3 +20,12 @@ js
setter called for 'js' with javascript
getter called for 'javascript'
javascript
__isExtensible__ called
true
__isSealed__ called
false
__isFrozen__ called
false
__freeze__ called
__seal__ called
__preventExtensions__ called

View File

@ -31,18 +31,21 @@
var js1 = new JSAdapter() {
__get__: function(name) {
Assert.assertTrue(this === js1);
return "js1->" + name;
}
};
var js2 = new JSAdapter() {
__get__: function(name) {
Assert.assertTrue(this === js2);
return "js2->" + name;
}
};
var js3 = new JSAdapter() {
__get__: function(name) {
Assert.assertTrue(this === js3);
return "js3->" + name;
}
};