Ignore:
Timestamp:
Nov 16, 2010, 1:11:26 PM (15 years ago)
Author:
[email protected]
Message:

JavaScriptCore: https://bugs.webkit.org/show_bug.cgi?id=49606

Reviewed by Oliver Hunt.

The bug here is that we read the prototype from the RHS argument using a regular
op_get_by_id before op_instanceof has checked that this is an object implementing
HasInstance. This incorrect behaviour gives rise to further unnecessary complexity
in the code base, since we have additional logic (implemented using the
GetByIdExceptionInfo data structures on CodeBlock) to convert not an object errors
from the get_by_id into invalid parameter errors. Having fixed this bug this code
is all redundant, since in these cases the get_by_id will never have been reached.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dump):
(JSC::CodeBlock::shrinkToFit):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::addExpressionInfo):

  • bytecode/Opcode.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitCheckHasInstance):

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::InstanceOfNode::emitBytecode):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::throwException):
(JSC::Interpreter::privateExecute):

  • jit/JIT.cpp:

(JSC::JIT::privateCompileMainPass):
(JSC::JIT::privateCompileSlowCases):

  • jit/JIT.h:
  • jit/JITOpcodes.cpp:

(JSC::JIT::emit_op_check_has_instance):
(JSC::JIT::emit_op_instanceof):
(JSC::JIT::emitSlow_op_check_has_instance):
(JSC::JIT::emitSlow_op_instanceof):

  • jit/JITOpcodes32_64.cpp:

(JSC::JIT::emit_op_check_has_instance):
(JSC::JIT::emit_op_instanceof):
(JSC::JIT::emitSlow_op_check_has_instance):
(JSC::JIT::emitSlow_op_instanceof):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:
  • runtime/ExceptionHelpers.cpp:

(JSC::createInterruptedExecutionException):
(JSC::createTerminatedExecutionException):
(JSC::createUndefinedVariableError):
(JSC::createNotAFunctionError):
(JSC::createNotAnObjectError):

  • runtime/ExceptionHelpers.h:
  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):

  • runtime/JSGlobalData.h:
  • runtime/JSNotAnObject.cpp:

(JSC::JSNotAnObject::toPrimitive):
(JSC::JSNotAnObject::getPrimitiveNumber):
(JSC::JSNotAnObject::toBoolean):
(JSC::JSNotAnObject::toNumber):
(JSC::JSNotAnObject::toString):
(JSC::JSNotAnObject::toObject):
(JSC::JSNotAnObject::getOwnPropertySlot):
(JSC::JSNotAnObject::getOwnPropertyDescriptor):
(JSC::JSNotAnObject::put):
(JSC::JSNotAnObject::deleteProperty):
(JSC::JSNotAnObject::getOwnPropertyNames):

  • runtime/JSNotAnObject.h:

(JSC::JSNotAnObject::JSNotAnObject):

  • runtime/JSObject.h:

(JSC::JSObject::isActivationObject):

  • runtime/JSValue.cpp:

(JSC::JSValue::toObjectSlowCase):
(JSC::JSValue::synthesizeObject):
(JSC::JSValue::synthesizePrototype):

LayoutTests: Bug 49606 - instanceof should only get the prototype property if the RHS operand implements HasInstance

Reviewed by Oliver Hunt.

  • fast/js/instanceof-XMLHttpRequest-expected.txt: Copied from LayoutTests/fast/js/instanceof-operator-expected.txt.
  • fast/js/instanceof-XMLHttpRequest.html: Copied from LayoutTests/fast/js/instanceof-operator.html.
  • fast/js/script-tests/instanceof-XMLHttpRequest.js: Copied from LayoutTests/fast/js/script-tests/instanceof-operator.js.
    • renamed existing testcase; these really test XMLHttpRequest objects, rather than the instanceof operator.
  • fast/js/instanceof-operator-expected.txt:
  • fast/js/script-tests/instanceof-operator.js:
    • added test case for: javascript: ({} instanceof { get prototype(){ alert("Error!"); } })
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSValue.cpp

    r67825 r72127  
    6363    if (isTrue() || isFalse())
    6464        return constructBooleanFromImmediateBoolean(exec, asValue());
     65
    6566    ASSERT(isUndefinedOrNull());
    66     JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull());
    67     throwError(exec, exception);
    68     return new (exec) JSNotAnObject(exec, exception);
     67    throwError(exec, createNotAnObjectError(exec, *this));
     68    return new (exec) JSNotAnObject(exec);
    6969}
    7070
     
    8888    if (isBoolean())
    8989        return constructBooleanFromImmediateBoolean(exec, asValue());
    90    
    91     JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull());
    92     throwError(exec, exception);
    93     return new (exec) JSNotAnObject(exec, exception);
     90
     91    ASSERT(isUndefinedOrNull());
     92    throwError(exec, createNotAnObjectError(exec, *this));
     93    return new (exec) JSNotAnObject(exec);
    9494}
    9595
     
    102102        return exec->lexicalGlobalObject()->booleanPrototype();
    103103
    104     JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull());
    105     throwError(exec, exception);
    106     return new (exec) JSNotAnObject(exec, exception);
     104    ASSERT(isUndefinedOrNull());
     105    throwError(exec, createNotAnObjectError(exec, *this));
     106    return new (exec) JSNotAnObject(exec);
    107107}
    108108
Note: See TracChangeset for help on using the changeset viewer.