Ignore:
Timestamp:
May 24, 2010, 11:46:49 AM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=39583
Move creation of 'this' object from caller to callee in construction.

Reviewed by Sam Weinig.

Presently the caller of a constructor is responsible for providing a this
object. Instead, move the object creation into a new op_create_this opcode,
planted in the head of the contructor bytecode for a function. Since the
prototype for the object is provided by performing a get_by_id on the callee,
also add a new get_callee opcode (this is used to get the callee JSFunction
into a register so that a normal get_by_id can be used).

Currently the caller is also responsible for detecting when op_construct is
performed on a JSFunction representing a host function, in which case an
exception is thrown – and this check currently takes place when constructing
the this object. Instead, mirroring the recent changes for non-host functions,
add a parallel code-path for native constructors to follow, with a thunk for
invoking native constructors provided by JITStubs, and a constructor-specific
NativeFunction on NativeExecutable. Provide an implementation of a host
constructor which will throw an exception.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dump):
(JSC::CodeBlock::getByIdExceptionInfoForBytecodeOffset):

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

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitConstruct):

  • bytecompiler/BytecodeGenerator.h:

(JSC::BytecodeGenerator::emitGetByIdExceptionInfo):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::privateExecute):

  • jit/JIT.cpp:

(JSC::JIT::privateCompileMainPass):

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

(JSC::JIT::compileOpCall):
(JSC::JIT::compileOpCallSlowCase):

  • jit/JITCall32_64.cpp:

(JSC::JIT::compileOpCall):
(JSC::JIT::compileOpCallSlowCase):

  • jit/JITOpcodes.cpp:

(JSC::JIT::privateCompileCTIMachineTrampolines):
(JSC::JIT::privateCompileCTINativeCall):
(JSC::JIT::emit_op_neq_null):
(JSC::JIT::emit_op_convert_this):
(JSC::JIT::emit_op_get_callee):
(JSC::JIT::emit_op_create_this):

  • jit/JITOpcodes32_64.cpp:

(JSC::JIT::privateCompileCTIMachineTrampolines):
(JSC::JIT::privateCompileCTINativeCall):
(JSC::JIT::emit_op_get_callee):
(JSC::JIT::emit_op_create_this):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):
(JSC::JITThunks::hostFunctionStub):

  • jit/JITStubs.h:

(JSC::JITThunks::ctiNativeConstruct):
(JSC::):

  • runtime/ExceptionHelpers.cpp:

(JSC::createNotAnObjectError):

  • runtime/Executable.h:

(JSC::NativeExecutable::create):
(JSC::NativeExecutable::NativeExecutable):

  • runtime/JSFunction.cpp:

(JSC::callHostFunctionAsConstructor):

  • runtime/JSFunction.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/bytecode/CodeBlock.cpp

    r59905 r60075  
    500500            break;
    501501        }
     502        case op_get_callee: {
     503            int r0 = (++it)->u.operand;
     504            printf("[%4d] op_get_callee %s\n", location, registerName(exec, r0).data());
     505            break;
     506        }
     507        case op_create_this: {
     508            int r0 = (++it)->u.operand;
     509            int r1 = (++it)->u.operand;
     510            printf("[%4d] create_this %s %s\n", location, registerName(exec, r0).data(), registerName(exec, r1).data());
     511            break;
     512        }
    502513        case op_convert_this: {
    503514            int r0 = (++it)->u.operand;
     
    10841095            int argCount = (++it)->u.operand;
    10851096            int registerOffset = (++it)->u.operand;
    1086             int proto = (++it)->u.operand;
    1087             int thisRegister = (++it)->u.operand;
    1088             printf("[%4d] construct\t %s, %d, %d, %s, %s\n", location, registerName(exec, func).data(), argCount, registerOffset, registerName(exec, proto).data(), registerName(exec, thisRegister).data());
     1097            printf("[%4d] construct\t %s, %d, %d\n", location, registerName(exec, func).data(), argCount, registerOffset);
    10891098            break;
    10901099        }
     
    16371646        return false;
    16381647
    1639     opcodeID = m_exceptionInfo->m_getByIdExceptionInfo[low - 1].isOpConstruct ? op_construct : op_instanceof;
     1648    opcodeID = m_exceptionInfo->m_getByIdExceptionInfo[low - 1].isOpCreateThis ? op_create_this : op_instanceof;
    16401649    return true;
    16411650}
Note: See TracChangeset for help on using the changeset viewer.