diff --git a/js/rhino/src/org/mozilla/javascript/Interpreter.java b/js/rhino/src/org/mozilla/javascript/Interpreter.java index 530974c5c05..824cea5bb9e 100644 --- a/js/rhino/src/org/mozilla/javascript/Interpreter.java +++ b/js/rhino/src/org/mozilla/javascript/Interpreter.java @@ -1924,7 +1924,7 @@ public class Interpreter --stackTop; Object lhs = stack[stackTop]; if (lhs == DBL_MRK) lhs = doubleWrap(sDbl[stackTop]); - boolean valBln = ScriptRuntime.instanceOf(scope, lhs, rhs); + boolean valBln = ScriptRuntime.instanceOf(lhs, rhs, scope); stack[stackTop] = valBln ? Boolean.TRUE : Boolean.FALSE; break; } diff --git a/js/rhino/src/org/mozilla/javascript/NativeArray.java b/js/rhino/src/org/mozilla/javascript/NativeArray.java index ecec663f8b1..a2b75444f55 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeArray.java +++ b/js/rhino/src/org/mozilla/javascript/NativeArray.java @@ -1023,7 +1023,7 @@ public class NativeArray extends IdScriptable { /* Put the target in the result array; only add it as an array * if it looks like one. */ - if (ScriptRuntime.instanceOf(scope, thisObj, ctor)) { + if (ScriptRuntime.instanceOf(thisObj, ctor, scope)) { length = getLengthProperty(thisObj); // Copy from the target object into the result @@ -1040,7 +1040,7 @@ public class NativeArray extends IdScriptable { * elements separately; otherwise, just copy the argument. */ for (int i = 0; i < args.length; i++) { - if (ScriptRuntime.instanceOf(scope, args[i], ctor)) { + if (ScriptRuntime.instanceOf(args[i], ctor, scope)) { // ScriptRuntime.instanceOf => instanceof Scriptable Scriptable arg = (Scriptable)args[i]; length = getLengthProperty(arg); diff --git a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java index f1f796f16ab..c190102995b 100644 --- a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java +++ b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java @@ -1638,7 +1638,8 @@ public class ScriptRuntime { * * @return a instanceof b */ - public static boolean instanceOf(Scriptable scope, Object a, Object b) { + public static boolean instanceOf(Object a, Object b, Scriptable scope) + { // Check RHS is an object if (! (b instanceof Scriptable)) { throw NativeGlobal.typeError0("msg.instanceof.not.object", scope); diff --git a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java index 979732170ee..3904e21b674 100644 --- a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java +++ b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java @@ -2552,24 +2552,12 @@ public class Codegen extends Interpreter { generateCodeFromNode(child.getNext(), node); genSimpleCompare(op, trueGOTO, falseGOTO); } else { - if (op == Token.INSTANCEOF) { - aload(variableObjectLocal); - generateCodeFromNode(child, node); - generateCodeFromNode(child.getNext(), node); - addScriptRuntimeInvoke( - "instanceOf", - "(Lorg/mozilla/javascript/Scriptable;" - +"Ljava/lang/Object;" - +"Ljava/lang/Object;" - +")Z"); - addByteCode(ByteCode.IFNE, trueGOTO); - addByteCode(ByteCode.GOTO, falseGOTO); - } else if (op == Token.IN) { + if (op == Token.INSTANCEOF || op == Token.IN) { generateCodeFromNode(child, node); generateCodeFromNode(child.getNext(), node); aload(variableObjectLocal); addScriptRuntimeInvoke( - "in", + (op == Token.INSTANCEOF) ? "instanceOf" : "in", "(Ljava/lang/Object;" +"Ljava/lang/Object;" +"Lorg/mozilla/javascript/Scriptable;" @@ -2699,24 +2687,14 @@ public class Codegen extends Interpreter { || op == Token.INSTANCEOF || op == Token.IN) { - if (op == Token.INSTANCEOF) - aload(variableObjectLocal); generateCodeFromNode(child, node); generateCodeFromNode(child.getNext(), node); int trueGOTO = acquireLabel(); int skip = acquireLabel(); - if (op == Token.INSTANCEOF) { - addScriptRuntimeInvoke( - "instanceOf", - "(Lorg/mozilla/javascript/Scriptable;" - +"Ljava/lang/Object;" - +"Ljava/lang/Object;" - +")Z"); - addByteCode(ByteCode.IFNE, trueGOTO); - } else if (op == Token.IN) { + if (op == Token.INSTANCEOF || op == Token.IN) { aload(variableObjectLocal); addScriptRuntimeInvoke( - "in", + (op == Token.INSTANCEOF) ? "instanceOf" : "in", "(Ljava/lang/Object;" +"Ljava/lang/Object;" +"Lorg/mozilla/javascript/Scriptable;"