diff options
Diffstat (limited to 'src/3rdparty/webkit/JavaScriptCore/runtime/ConstructData.cpp')
-rw-r--r-- | src/3rdparty/webkit/JavaScriptCore/runtime/ConstructData.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/ConstructData.cpp b/src/3rdparty/webkit/JavaScriptCore/runtime/ConstructData.cpp index 7ee59d7..b19ae04 100644 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/ConstructData.cpp +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/ConstructData.cpp @@ -25,18 +25,46 @@ #include "config.h" #include "ConstructData.h" +#include "ExceptionHelpers.h" +#include "Interpreter.h" #include "JSFunction.h" +#include "JSGlobalObject.h" namespace JSC { -JSObject* construct(ExecState* exec, JSValue object, ConstructType constructType, const ConstructData& constructData, const ArgList& args) +JSObject* construct(ExecState* exec, JSValue callee, ConstructType constructType, const ConstructData& constructData, const ArgList& args) { - if (constructType == ConstructTypeHost) - return constructData.native.function(exec, asObject(object), args); + if (constructType == ConstructTypeHost) { + Structure* structure; + JSValue prototype = callee.get(exec, exec->propertyNames().prototype); + if (prototype.isObject()) + structure = asObject(prototype)->inheritorID(); + else + structure = exec->lexicalGlobalObject()->emptyObjectStructure(); + JSObject* thisObj = new (exec) JSObject(structure); + + ScopeChainNode* scopeChain = exec->scopeChain(); + Interpreter *interp = exec->interpreter(); + Register *oldEnd = interp->registerFile().end(); + int argc = 1 + args.size(); // implicit "this" parameter + if (!interp->registerFile().grow(oldEnd + argc + RegisterFile::CallFrameHeaderSize)) + return asObject(createStackOverflowError(exec)); + CallFrame* newCallFrame = CallFrame::create(oldEnd); + size_t dst = 0; + newCallFrame[0] = JSValue(thisObj); + ArgList::const_iterator it; + for (it = args.begin(); it != args.end(); ++it) + newCallFrame[++dst] = *it; + newCallFrame += argc + RegisterFile::CallFrameHeaderSize; + newCallFrame->init(0, /*vPC=*/0, scopeChain, exec, 0, argc, asObject(callee)); + JSObject *result = constructData.native.function(newCallFrame, asObject(callee), args); + interp->registerFile().shrink(oldEnd); + return result; + } ASSERT(constructType == ConstructTypeJS); // FIXME: Can this be done more efficiently using the constructData? - return asFunction(object)->construct(exec, args); + return asFunction(callee)->construct(exec, args); } } // namespace JSC |