Ignore:
Timestamp:
May 12, 2009, 2:18:44 AM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2009-05-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

instanceof should throw if the constructor being tested does not implement
'HasInstance" (i.e. is a function). Instead we were returning false.

  • interpreter/Interpreter.cpp: (JSC::isInvalidParamForIn): (JSC::isInvalidParamForInstanceOf): (JSC::Interpreter::privateExecute):
  • jit/JITStubs.cpp: (JSC::JITStubs::cti_op_instanceof):
  • tests/mozilla/ecma_2/instanceof/instanceof-003.js:

Fix broken test case.

  • tests/mozilla/ecma_2/instanceof/regress-7635.js:

Remove broken test case (was an exact duplicate of a test in instanceof-003.js).

LayoutTests:

2009-05-12 Gavin Barraclough <[email protected]>

Reviewed by Oliver Hunt.

Test was checked in with one test case disabled since it exposed an existing bug;
enable it now.

  • fast/js/instance-of-immediates-expected.txt:
  • fast/js/resources/instance-of-immediates.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r43559 r43560  
    318318}
    319319
    320 static NEVER_INLINE bool isNotObject(CallFrame* callFrame, bool forInstanceOf, CodeBlock* codeBlock, const Instruction* vPC, JSValue value, JSValue& exceptionData)
     320static NEVER_INLINE bool isInvalidParamForIn(CallFrame* callFrame, CodeBlock* codeBlock, const Instruction* vPC, JSValue value, JSValue& exceptionData)
    321321{
    322322    if (value.isObject())
    323323        return false;
    324     exceptionData = createInvalidParamError(callFrame, forInstanceOf ? "instanceof" : "in" , value, vPC - codeBlock->instructions().begin(), codeBlock);
     324    exceptionData = createInvalidParamError(callFrame, "in" , value, vPC - codeBlock->instructions().begin(), codeBlock);
     325    return true;
     326}
     327
     328static NEVER_INLINE bool isInvalidParamForInstanceOf(CallFrame* callFrame, CodeBlock* codeBlock, const Instruction* vPC, JSValue value, JSValue& exceptionData)
     329{
     330    if (value.isObject() && asObject(value)->structure()->typeInfo().implementsHasInstance())
     331        return false;
     332    exceptionData = createInvalidParamError(callFrame, "instanceof" , value, vPC - codeBlock->instructions().begin(), codeBlock);
    325333    return true;
    326334}
     
    18131821        JSValue baseVal = callFrame[base].jsValue();
    18141822
    1815         if (isNotObject(callFrame, true, callFrame->codeBlock(), vPC, baseVal, exceptionValue))
     1823        if (isInvalidParamForInstanceOf(callFrame, callFrame->codeBlock(), vPC, baseVal, exceptionValue))
    18161824            goto vm_throw;
    18171825
    1818         JSObject* baseObj = asObject(baseVal);
    1819         if (baseObj->structure()->typeInfo().implementsHasInstance()) {
    1820             bool result = baseObj->hasInstance(callFrame, callFrame[value].jsValue(), callFrame[baseProto].jsValue());
    1821             CHECK_FOR_EXCEPTION();
    1822             callFrame[dst] = jsBoolean(result);
    1823         } else
    1824             callFrame[dst] = jsBoolean(false);
     1826        bool result = asObject(baseVal)->hasInstance(callFrame, callFrame[value].jsValue(), callFrame[baseProto].jsValue());
     1827        CHECK_FOR_EXCEPTION();
     1828        callFrame[dst] = jsBoolean(result);
    18251829
    18261830        vPC += 5;
     
    19391943
    19401944        JSValue baseVal = callFrame[base].jsValue();
    1941         if (isNotObject(callFrame, false, callFrame->codeBlock(), vPC, baseVal, exceptionValue))
     1945        if (isInvalidParamForIn(callFrame, callFrame->codeBlock(), vPC, baseVal, exceptionValue))
    19421946            goto vm_throw;
    19431947
Note: See TracChangeset for help on using the changeset viewer.