8148924: Inconsistent "this" context in JSAdapter adaptee function calls
Reviewed-by: jlaskey
This commit is contained in:
parent
b82b0af8c2
commit
6a77385b4d
@ -365,7 +365,7 @@ public final class NativeJSAdapter extends ScriptObject {
|
|||||||
|
|
||||||
Object obj;
|
Object obj;
|
||||||
if (func instanceof ScriptFunction) {
|
if (func instanceof ScriptFunction) {
|
||||||
obj = ScriptRuntime.apply((ScriptFunction)func, adaptee);
|
obj = ScriptRuntime.apply((ScriptFunction)func, this);
|
||||||
} else {
|
} else {
|
||||||
obj = new NativeArray(0);
|
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) {
|
private Object callAdaptee(final Object retValue, final String name, final Object... args) {
|
||||||
final Object func = adaptee.get(name);
|
final Object func = adaptee.get(name);
|
||||||
if (func instanceof ScriptFunction) {
|
if (func instanceof ScriptFunction) {
|
||||||
return ScriptRuntime.apply((ScriptFunction)func, adaptee, args);
|
return ScriptRuntime.apply((ScriptFunction)func, this, args);
|
||||||
}
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
var obj = new JSAdapter() {
|
var obj = new JSAdapter() {
|
||||||
__getIds__: function() {
|
__getIds__: function() {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("__getIds__ called");
|
print("__getIds__ called");
|
||||||
return [ "foo", "bar" ];
|
return [ "foo", "bar" ];
|
||||||
}
|
}
|
||||||
|
@ -30,39 +30,81 @@
|
|||||||
|
|
||||||
var obj = new JSAdapter() {
|
var obj = new JSAdapter() {
|
||||||
__get__: function(name) {
|
__get__: function(name) {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("getter called for '" + name + "'"); return name;
|
print("getter called for '" + name + "'"); return name;
|
||||||
},
|
},
|
||||||
|
|
||||||
__put__: function(name, value) {
|
__put__: function(name, value) {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("setter called for '" + name + "' with " + value);
|
print("setter called for '" + name + "' with " + value);
|
||||||
},
|
},
|
||||||
|
|
||||||
__call__: function(name, arg1, arg2) {
|
__call__: function(name, arg1, arg2) {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("method '" + name + "' called with " + arg1 + ", " + arg2);
|
print("method '" + name + "' called with " + arg1 + ", " + arg2);
|
||||||
},
|
},
|
||||||
|
|
||||||
__new__: function(arg1, arg2) {
|
__new__: function(arg1, arg2) {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("new with " + arg1 + ", " + arg2);
|
print("new with " + arg1 + ", " + arg2);
|
||||||
},
|
},
|
||||||
|
|
||||||
__getKeys__: function() {
|
__getKeys__: function() {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("__getKeys__ called");
|
print("__getKeys__ called");
|
||||||
return [ "foo", "bar" ];
|
return [ "foo", "bar" ];
|
||||||
},
|
},
|
||||||
|
|
||||||
__getValues__: function() {
|
__getValues__: function() {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("__getValues__ called");
|
print("__getValues__ called");
|
||||||
return [ "fooval", "barval" ];
|
return [ "fooval", "barval" ];
|
||||||
},
|
},
|
||||||
|
|
||||||
__has__: function(name) {
|
__has__: function(name) {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("__has__ called with '" + name + "'");
|
print("__has__ called with '" + name + "'");
|
||||||
return name == "js";
|
return name == "js";
|
||||||
},
|
},
|
||||||
|
|
||||||
__delete__: function(name) {
|
__delete__: function(name) {
|
||||||
|
Assert.assertTrue(this === obj);
|
||||||
print("__delete__ called with '" + name + "'");
|
print("__delete__ called with '" + name + "'");
|
||||||
return true;
|
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"]);
|
print(obj["js"]);
|
||||||
obj["js"] = "javascript";
|
obj["js"] = "javascript";
|
||||||
print(obj["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);
|
||||||
|
@ -20,3 +20,12 @@ js
|
|||||||
setter called for 'js' with javascript
|
setter called for 'js' with javascript
|
||||||
getter called for 'javascript'
|
getter called for 'javascript'
|
||||||
javascript
|
javascript
|
||||||
|
__isExtensible__ called
|
||||||
|
true
|
||||||
|
__isSealed__ called
|
||||||
|
false
|
||||||
|
__isFrozen__ called
|
||||||
|
false
|
||||||
|
__freeze__ called
|
||||||
|
__seal__ called
|
||||||
|
__preventExtensions__ called
|
||||||
|
@ -31,18 +31,21 @@
|
|||||||
|
|
||||||
var js1 = new JSAdapter() {
|
var js1 = new JSAdapter() {
|
||||||
__get__: function(name) {
|
__get__: function(name) {
|
||||||
|
Assert.assertTrue(this === js1);
|
||||||
return "js1->" + name;
|
return "js1->" + name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var js2 = new JSAdapter() {
|
var js2 = new JSAdapter() {
|
||||||
__get__: function(name) {
|
__get__: function(name) {
|
||||||
|
Assert.assertTrue(this === js2);
|
||||||
return "js2->" + name;
|
return "js2->" + name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var js3 = new JSAdapter() {
|
var js3 = new JSAdapter() {
|
||||||
__get__: function(name) {
|
__get__: function(name) {
|
||||||
|
Assert.assertTrue(this === js3);
|
||||||
return "js3->" + name;
|
return "js3->" + name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user