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/runtime/JSFunction.cpp

    r59974 r60075  
    2929#include "CommonIdentifiers.h"
    3030#include "CallFrame.h"
     31#include "ExceptionHelpers.h"
    3132#include "FunctionPrototype.h"
    3233#include "JSGlobalObject.h"
     
    4142
    4243namespace JSC {
     44
     45JSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState* exec, JSObject* constructor, JSValue, const ArgList&)
     46{
     47    CodeBlock* codeBlock = exec->callerFrame()->codeBlock();
     48    unsigned vPCIndex = codeBlock->bytecodeOffset(exec, exec->returnPC());
     49    exec->setException(createNotAConstructorError(exec, constructor, vPCIndex, codeBlock));
     50    return JSValue();
     51}
    4352
    4453ASSERT_CLASS_FITS_IN_CELL(JSFunction);
Note: See TracChangeset for help on using the changeset viewer.