Commit 11d351a9 authored by barraclough@apple.com's avatar barraclough@apple.com

Bug 40187 - Change function signature of NativeConstructor to match NativeFunction

Reviewed by Oliver Hunt.

Mostly for consistency, but constructor & args arguments are redundant,
and this will help if we wish to be able to JIT calls to more constructors.

JavaScriptCore: 

* API/JSCallbackConstructor.cpp:
(JSC::constructJSCallback):
* API/JSCallbackObject.h:
* API/JSCallbackObjectFunctions.h:
(JSC::::construct):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::executeConstruct):
* interpreter/Interpreter.h:
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION):
* runtime/ArrayConstructor.cpp:
(JSC::constructWithArrayConstructor):
* runtime/BooleanConstructor.cpp:
(JSC::constructWithBooleanConstructor):
* runtime/ConstructData.cpp:
(JSC::construct):
* runtime/ConstructData.h:
* runtime/DateConstructor.cpp:
(JSC::constructWithDateConstructor):
* runtime/Error.cpp:
(JSC::constructNativeError):
(JSC::Error::create):
* runtime/ErrorConstructor.cpp:
(JSC::constructWithErrorConstructor):
* runtime/FunctionConstructor.cpp:
(JSC::constructWithFunctionConstructor):
* runtime/NativeErrorConstructor.cpp:
(JSC::constructWithNativeErrorConstructor):
* runtime/NativeErrorConstructor.h:
(JSC::NativeErrorConstructor::errorStructure):
* runtime/NumberConstructor.cpp:
(JSC::constructWithNumberConstructor):
* runtime/ObjectConstructor.cpp:
(JSC::constructWithObjectConstructor):
* runtime/RegExpConstructor.cpp:
(JSC::constructWithRegExpConstructor):
* runtime/StringConstructor.cpp:
(JSC::constructWithStringConstructor):

WebCore: 

* bindings/js/JSArrayBufferConstructor.cpp:
(WebCore::constructCanvasArrayBuffer):
* bindings/js/JSAudioConstructor.cpp:
(WebCore::constructAudio):
* bindings/js/JSEventSourceConstructor.cpp:
(WebCore::constructEventSource):
* bindings/js/JSFloatArrayConstructor.cpp:
(WebCore::constructCanvasFloatArray):
* bindings/js/JSImageConstructor.cpp:
(WebCore::constructImage):
* bindings/js/JSInt16ArrayConstructor.cpp:
(WebCore::constructCanvasShortArray):
* bindings/js/JSInt32ArrayConstructor.cpp:
(WebCore::constructCanvasIntArray):
* bindings/js/JSInt8ArrayConstructor.cpp:
(WebCore::constructCanvasByteArray):
* bindings/js/JSMessageChannelConstructor.cpp:
(WebCore::JSMessageChannelConstructor::construct):
* bindings/js/JSMessageChannelConstructor.h:
* bindings/js/JSOptionConstructor.cpp:
(WebCore::constructHTMLOptionElement):
* bindings/js/JSSharedWorkerConstructor.cpp:
(WebCore::constructSharedWorker):
* bindings/js/JSUint16ArrayConstructor.cpp:
(WebCore::constructCanvasUnsignedShortArray):
* bindings/js/JSUint32ArrayConstructor.cpp:
(WebCore::constructCanvasUnsignedIntArray):
* bindings/js/JSUint8ArrayConstructor.cpp:
(WebCore::constructCanvasUnsignedByteArray):
* bindings/js/JSWebKitCSSMatrixConstructor.cpp:
(WebCore::constructWebKitCSSMatrix):
* bindings/js/JSWebKitPointConstructor.cpp:
(WebCore::constructWebKitPoint):
* bindings/js/JSWebSocketConstructor.cpp:
(WebCore::constructWebSocket):
* bindings/js/JSWorkerConstructor.cpp:
(WebCore::constructWorker):
* bindings/js/JSXMLHttpRequestConstructor.cpp:
(WebCore::constructXMLHttpRequest):
* bindings/js/JSXSLTProcessorConstructor.cpp:
(WebCore::constructXSLTProcessor):
* bindings/scripts/CodeGeneratorJS.pm:
* bridge/runtime_object.cpp:
(JSC::Bindings::callRuntimeConstructor):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@60708 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 960c575d
......@@ -52,17 +52,18 @@ JSCallbackConstructor::~JSCallbackConstructor()
JSClassRelease(m_class);
}
static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec)
{
JSObject* constructor = exec->callee();
JSContextRef ctx = toRef(exec);
JSObjectRef constructorRef = toRef(constructor);
JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
if (callback) {
int argumentCount = static_cast<int>(args.size());
int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
arguments[i] = toRef(exec, args.at(i));
arguments[i] = toRef(exec, exec->argument(i));
JSValueRef exception = 0;
JSObjectRef result;
......@@ -72,10 +73,10 @@ static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, con
}
if (exception)
exec->setException(toJS(exec, exception));
return toJS(result);
return JSValue::encode(toJS(result));
}
return toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0));
return JSValue::encode(toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0)));
}
ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData)
......
......@@ -183,7 +183,7 @@ private:
static JSCallbackObject* asCallbackObject(JSValue);
static EncodedJSValue JSC_HOST_CALL call(ExecState*);
static JSObject* construct(ExecState*, JSObject* constructor, const ArgList&);
static EncodedJSValue JSC_HOST_CALL construct(ExecState*);
static JSValue staticValueGetter(ExecState*, JSValue, const Identifier&);
static JSValue staticFunctionGetter(ExecState*, JSValue, const Identifier&);
......
......@@ -308,17 +308,18 @@ ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructD
}
template <class Base>
JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args)
EncodedJSValue JSCallbackObject<Base>::construct(ExecState* exec)
{
JSObject* constructor = exec->callee();
JSContextRef execRef = toRef(exec);
JSObjectRef constructorRef = toRef(constructor);
for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
int argumentCount = static_cast<int>(args.size());
int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
arguments[i] = toRef(exec, args.at(i));
arguments[i] = toRef(exec, exec->argument(i));
JSValueRef exception = 0;
JSObject* result;
{
......@@ -327,12 +328,12 @@ JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* construct
}
if (exception)
exec->setException(toJS(exec, exception));
return result;
return JSValue::encode(result);
}
}
ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
return 0;
return JSValue::encode(JSValue());
}
template <class Base>
......
2010-06-04 Gavin Barraclough <barraclough@apple.com>
Reviewed by Oliver Hunt.
Bug 40187 - Change function signature of NativeConstructor to match NativeFunction
Mostly for consistency, but constructor & args arguments are redundant,
and this will help if we wish to be able to JIT calls to more constructors.
* API/JSCallbackConstructor.cpp:
(JSC::constructJSCallback):
* API/JSCallbackObject.h:
* API/JSCallbackObjectFunctions.h:
(JSC::::construct):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::executeConstruct):
* interpreter/Interpreter.h:
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION):
* runtime/ArrayConstructor.cpp:
(JSC::constructWithArrayConstructor):
* runtime/BooleanConstructor.cpp:
(JSC::constructWithBooleanConstructor):
* runtime/ConstructData.cpp:
(JSC::construct):
* runtime/ConstructData.h:
* runtime/DateConstructor.cpp:
(JSC::constructWithDateConstructor):
* runtime/Error.cpp:
(JSC::constructNativeError):
(JSC::Error::create):
* runtime/ErrorConstructor.cpp:
(JSC::constructWithErrorConstructor):
* runtime/FunctionConstructor.cpp:
(JSC::constructWithFunctionConstructor):
* runtime/NativeErrorConstructor.cpp:
(JSC::constructWithNativeErrorConstructor):
* runtime/NativeErrorConstructor.h:
(JSC::NativeErrorConstructor::errorStructure):
* runtime/NumberConstructor.cpp:
(JSC::constructWithNumberConstructor):
* runtime/ObjectConstructor.cpp:
(JSC::constructWithObjectConstructor):
* runtime/RegExpConstructor.cpp:
(JSC::constructWithRegExpConstructor):
* runtime/StringConstructor.cpp:
(JSC::constructWithStringConstructor):
2010-06-04 Tony Gentilcore <tonyg@chromium.org>
Reviewed by Adam Barth.
......
......@@ -795,66 +795,99 @@ JSValue Interpreter::executeCall(CallFrame* callFrame, JSObject* function, CallT
return result;
}
JSValue Interpreter::executeConstruct(FunctionExecutable* functionExecutable, CallFrame* callFrame, JSFunction* function, JSObject* thisObj, const ArgList& args, ScopeChainNode* scopeChain, JSValue* exception)
JSObject* Interpreter::executeConstruct(CallFrame* callFrame, JSObject* constructor, ConstructType constructType, const ConstructData& constructData, const ArgList& args, JSValue* exception)
{
ASSERT(!scopeChain->globalData->exception);
ASSERT(!callFrame->hadException());
if (m_reentryDepth >= MaxSmallThreadReentryDepth) {
if (m_reentryDepth >= callFrame->globalData().maxReentryDepth) {
*exception = createStackOverflowError(callFrame);
return jsNull();
return 0;
}
}
Register* oldEnd = m_registerFile.end();
int argc = 1 + args.size(); // implicit "this" parameter
int argCount = 1 + args.size(); // implicit "this" parameter
size_t registerOffset = argCount + RegisterFile::CallFrameHeaderSize;
if (!m_registerFile.grow(oldEnd + argc)) {
if (!m_registerFile.grow(oldEnd + registerOffset)) {
*exception = createStackOverflowError(callFrame);
return jsNull();
return 0;
}
CallFrame* newCallFrame = CallFrame::create(oldEnd);
size_t dst = 0;
newCallFrame->r(0) = JSValue(thisObj);
ArgList::const_iterator end = args.end();
for (ArgList::const_iterator it = args.begin(); it != end; ++it)
newCallFrame->r(++dst) = *it;
CodeBlock* codeBlock = &functionExecutable->bytecodeForConstruct(callFrame, scopeChain);
newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
if (UNLIKELY(!newCallFrame)) {
*exception = createStackOverflowError(callFrame);
if (constructType == ConstructTypeJS) {
ScopeChainNode* constructDataScopeChain = constructData.js.scopeChain;
CodeBlock* newCodeBlock = &constructData.js.functionExecutable->bytecodeForConstruct(callFrame, constructDataScopeChain);
newCallFrame = slideRegisterWindowForCall(newCodeBlock, &m_registerFile, newCallFrame, registerOffset, argCount);
if (UNLIKELY(!newCallFrame)) {
*exception = createStackOverflowError(callFrame);
m_registerFile.shrink(oldEnd);
return 0;
}
newCallFrame->init(newCodeBlock, 0, constructDataScopeChain, callFrame->addHostCallFrameFlag(), argCount, constructor);
DynamicGlobalObjectScope globalObjectScope(newCallFrame, constructDataScopeChain->globalObject);
Profiler** profiler = Profiler::enabledProfilerReference();
if (*profiler)
(*profiler)->willExecute(newCallFrame, constructor);
JSValue result;
{
SamplingTool::CallRecord callRecord(m_sampler.get());
m_reentryDepth++;
#if ENABLE(JIT)
result = constructData.js.functionExecutable->jitCodeForConstruct(newCallFrame, constructDataScopeChain).execute(&m_registerFile, newCallFrame, constructDataScopeChain->globalData, exception);
#else
result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
#endif
m_reentryDepth--;
}
if (*profiler)
(*profiler)->didExecute(newCallFrame, constructor);
m_registerFile.shrink(oldEnd);
return jsNull();
if (callFrame->hadException())
return 0;
ASSERT(result.isObject());
return asObject(result);
}
// a 0 codeBlock indicates a built-in caller
newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), argc, function);
DynamicGlobalObjectScope globalObjectScope(callFrame, scopeChain->globalObject);
ASSERT(constructType == ConstructTypeHost);
ScopeChainNode* scopeChain = callFrame->scopeChain();
newCallFrame = CallFrame::create(newCallFrame->registers() + registerOffset);
newCallFrame->init(0, 0, scopeChain, callFrame->addHostCallFrameFlag(), argCount, constructor);
DynamicGlobalObjectScope globalObjectScope(newCallFrame, scopeChain->globalObject);
Profiler** profiler = Profiler::enabledProfilerReference();
if (*profiler)
(*profiler)->willExecute(callFrame, function);
(*profiler)->willExecute(newCallFrame, constructor);
JSValue result;
{
SamplingTool::CallRecord callRecord(m_sampler.get());
m_reentryDepth++;
#if ENABLE(JIT)
result = functionExecutable->jitCodeForConstruct(newCallFrame, scopeChain).execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
#else
result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
#endif
m_reentryDepth--;
SamplingTool::HostCallRecord callRecord(m_sampler.get());
result = JSValue::decode(constructData.native.function(newCallFrame));
}
if (*profiler)
(*profiler)->didExecute(callFrame, function);
(*profiler)->didExecute(newCallFrame, constructor);
m_registerFile.shrink(oldEnd);
return result;
if (callFrame->hadException())
return 0;
ASSERT(result.isObject());
return asObject(result);
}
CallFrameClosure Interpreter::prepareForRepeatCall(FunctionExecutable* FunctionExecutable, CallFrame* callFrame, JSFunction* function, int argCount, ScopeChainNode* scopeChain, JSValue* exception)
......
......@@ -96,7 +96,7 @@ namespace JSC {
JSValue execute(ProgramExecutable*, CallFrame*, ScopeChainNode*, JSObject* thisObj, JSValue* exception);
JSValue executeCall(CallFrame*, JSObject* function, CallType, const CallData&, JSValue thisValue, const ArgList&, JSValue* exception);
JSValue executeConstruct(FunctionExecutable*, CallFrame*, JSFunction*, JSObject* thisObj, const ArgList& args, ScopeChainNode*, JSValue* exception);
JSObject* executeConstruct(CallFrame*, JSObject* function, ConstructType, const ConstructData&, const ArgList&, JSValue* exception);
JSValue execute(EvalExecutable* evalNode, CallFrame* exec, JSObject* thisObj, ScopeChainNode* scopeChain, JSValue* exception);
JSValue retrieveArguments(CallFrame*, JSFunction*) const;
......
......@@ -2163,31 +2163,36 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_construct_NotJSConstruct)
{
STUB_INIT_STACK_FRAME(stackFrame);
CallFrame* callFrame = stackFrame.callFrame;
JSValue constrVal = stackFrame.args[0].jsValue();
int argCount = stackFrame.args[2].int32();
ConstructData constructData;
ConstructType constructType = getConstructData(constrVal, constructData);
ASSERT(constructType != ConstructTypeJS);
if (constructType == ConstructTypeHost) {
int registerOffset = stackFrame.args[1].int32();
Register* thisRegister = callFrame->registers() + registerOffset - RegisterFile::CallFrameHeaderSize - argCount;
ArgList argList(thisRegister + 1, argCount - 1);
int argCount = stackFrame.args[2].int32();
CallFrame* previousCallFrame = stackFrame.callFrame;
CallFrame* callFrame = CallFrame::create(previousCallFrame->registers() + registerOffset);
JSValue returnValue;
callFrame->init(0, static_cast<Instruction*>((STUB_RETURN_ADDRESS).value()), previousCallFrame->scopeChain(), previousCallFrame, argCount, asObject(constrVal));
stackFrame.callFrame = callFrame;
EncodedJSValue returnValue;
{
SamplingTool::HostCallRecord callRecord(CTI_SAMPLER);
returnValue = constructData.native.function(callFrame, asObject(constrVal), argList);
returnValue = constructData.native.function(callFrame);
}
stackFrame.callFrame = previousCallFrame;
CHECK_FOR_EXCEPTION();
return JSValue::encode(returnValue);
return returnValue;
}
ASSERT(constructType == ConstructTypeNone);
CallFrame* callFrame = stackFrame.callFrame;
CodeBlock* codeBlock = callFrame->codeBlock();
unsigned vPCIndex = codeBlock->bytecodeOffset(callFrame, STUB_RETURN_ADDRESS);
stackFrame.globalData->exception = createNotAConstructorError(callFrame, constrVal, vPCIndex, codeBlock);
......
......@@ -64,9 +64,10 @@ static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgLi
return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure(), args);
}
static JSObject* constructWithArrayConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec)
{
return constructArrayWithSizeQuirk(exec, args);
ArgList args(exec);
return JSValue::encode(constructArrayWithSizeQuirk(exec, args));
}
// ECMA 15.4.2
......
......@@ -45,9 +45,10 @@ JSObject* constructBoolean(ExecState* exec, const ArgList& args)
return obj;
}
static JSObject* constructWithBooleanConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec)
{
return constructBoolean(exec, args);
ArgList args(exec);
return JSValue::encode(constructBoolean(exec, args));
}
ConstructType BooleanConstructor::getConstructData(ConstructData& constructData)
......
......@@ -33,27 +33,10 @@
namespace JSC {
JSObject* construct(ExecState* exec, JSValue object, ConstructType constructType, const ConstructData& constructData, const ArgList& args)
JSObject* construct(ExecState* exec, JSValue constructorObject, ConstructType constructType, const ConstructData& constructData, const ArgList& args)
{
if (constructType == ConstructTypeHost)
return constructData.native.function(exec, asObject(object), args);
ASSERT(constructType == ConstructTypeJS);
JSFunction* jsFunction = asFunction(object);
ASSERT(!jsFunction->isHostFunction());
Structure* structure;
JSValue prototype = jsFunction->get(exec, exec->propertyNames().prototype);
if (prototype.isObject())
structure = asObject(prototype)->inheritorID();
else
structure = exec->lexicalGlobalObject()->emptyObjectStructure();
JSObject* thisObj = new (exec) JSObject(structure);
JSValue result = exec->interpreter()->executeConstruct(jsFunction->jsExecutable(), exec, jsFunction, thisObj, args, jsFunction->scope().node(), exec->exceptionSlot());
if (exec->hadException() || !result.isObject())
return thisObj;
return asObject(result);
ASSERT(constructType == ConstructTypeJS || constructType == ConstructTypeHost);
return exec->interpreter()->executeConstruct(exec, asObject(constructorObject), constructType, constructData, args, exec->exceptionSlot());
}
} // namespace JSC
......@@ -29,13 +29,14 @@
#ifndef ConstructData_h
#define ConstructData_h
#include "JSValue.h"
namespace JSC {
class ArgList;
class ExecState;
class FunctionExecutable;
class JSObject;
class JSValue;
class ScopeChainNode;
enum ConstructType {
......@@ -44,7 +45,7 @@ namespace JSC {
ConstructTypeJS
};
typedef JSObject* (*NativeConstructor)(ExecState*, JSObject*, const ArgList&);
typedef EncodedJSValue (JSC_HOST_CALL *NativeConstructor)(ExecState*);
union ConstructData {
struct {
......
......@@ -116,9 +116,10 @@ JSObject* constructDate(ExecState* exec, const ArgList& args)
return new (exec) DateInstance(exec, value);
}
static JSObject* constructWithDateConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithDateConstructor(ExecState* exec)
{
return constructDate(exec, args);
ArgList args(exec);
return JSValue::encode(constructDate(exec, args));
}
ConstructType DateConstructor::getConstructData(ConstructData& constructData)
......
......@@ -38,50 +38,50 @@ const char* expressionBeginOffsetPropertyName = "expressionBeginOffset";
const char* expressionCaretOffsetPropertyName = "expressionCaretOffset";
const char* expressionEndOffsetPropertyName = "expressionEndOffset";
static JSObject* constructNativeError(ExecState* exec, const UString& message, NativeErrorConstructor* constructor, const char* name)
{
ErrorInstance* object = new (exec) ErrorInstance(constructor->errorStructure());
JSString* messageString = message.isEmpty() ? jsString(exec, name) : jsString(exec, message);
object->putDirect(exec->propertyNames().message, messageString);
return object;
}
JSObject* Error::create(ExecState* exec, ErrorType type, const UString& message, int lineNumber, intptr_t sourceID, const UString& sourceURL)
{
JSObject* constructor;
const char* name;
JSObject* error;
switch (type) {
case EvalError:
constructor = exec->lexicalGlobalObject()->evalErrorConstructor();
name = "Evaluation error";
error = constructNativeError(exec, message, exec->lexicalGlobalObject()->evalErrorConstructor(), "Evaluation error");
break;
case RangeError:
constructor = exec->lexicalGlobalObject()->rangeErrorConstructor();
name = "Range error";
error = constructNativeError(exec, message, exec->lexicalGlobalObject()->rangeErrorConstructor(), "Range error");
break;
case ReferenceError:
constructor = exec->lexicalGlobalObject()->referenceErrorConstructor();
name = "Reference error";
error = constructNativeError(exec, message, exec->lexicalGlobalObject()->referenceErrorConstructor(), "Reference error");
break;
case SyntaxError:
constructor = exec->lexicalGlobalObject()->syntaxErrorConstructor();
name = "Syntax error";
error = constructNativeError(exec, message, exec->lexicalGlobalObject()->syntaxErrorConstructor(), "Syntax error");
break;
case TypeError:
constructor = exec->lexicalGlobalObject()->typeErrorConstructor();
name = "Type error";
error = constructNativeError(exec, message, exec->lexicalGlobalObject()->typeErrorConstructor(), "Type error");
break;
case URIError:
constructor = exec->lexicalGlobalObject()->URIErrorConstructor();
name = "URI error";
error = constructNativeError(exec, message, exec->lexicalGlobalObject()->URIErrorConstructor(), "URI error");
break;
default:
constructor = exec->lexicalGlobalObject()->errorConstructor();
name = "Error";
break;
JSObject* constructor = exec->lexicalGlobalObject()->errorConstructor();
const char* name = "Error";
MarkedArgumentBuffer args;
if (message.isEmpty())
args.append(jsString(exec, name));
else
args.append(jsString(exec, message));
ConstructData constructData;
ConstructType constructType = constructor->getConstructData(constructData);
error = construct(exec, constructor, constructType, constructData, args);
}
MarkedArgumentBuffer args;
if (message.isEmpty())
args.append(jsString(exec, name));
else
args.append(jsString(exec, message));
ConstructData constructData;
ConstructType constructType = constructor->getConstructData(constructData);
JSObject* error = construct(exec, constructor, constructType, constructData, args);
if (lineNumber != -1)
error->putWithAttributes(exec, Identifier(exec, "line"), jsNumber(exec, lineNumber), ReadOnly | DontDelete);
if (sourceID != -1)
......
......@@ -46,9 +46,10 @@ ErrorInstance* constructError(ExecState* exec, const ArgList& args)
return obj;
}
static JSObject* constructWithErrorConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec)
{
return constructError(exec, args);
ArgList args(exec);
return JSValue::encode(constructError(exec, args));
}
ConstructType ErrorConstructor::getConstructData(ConstructData& constructData)
......
......@@ -44,9 +44,10 @@ FunctionConstructor::FunctionConstructor(ExecState* exec, JSGlobalObject* global
putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontDelete | DontEnum);
}
static JSObject* constructWithFunctionConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithFunctionConstructor(ExecState* exec)
{
return constructFunction(exec, args);
ArgList args(exec);
return JSValue::encode(constructFunction(exec, args));
}
ConstructType FunctionConstructor::getConstructData(ConstructData& constructData)
......
......@@ -51,9 +51,10 @@ ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList&
return object;
}
static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithNativeErrorConstructor(ExecState* exec)
{
return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
ArgList args(exec);
return JSValue::encode(static_cast<NativeErrorConstructor*>(exec->callee())->construct(exec, args));
}
ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData)
......
......@@ -37,6 +37,8 @@ namespace JSC {
ErrorInstance* construct(ExecState*, const ArgList&);
Structure* errorStructure() { return m_errorStructure.get(); }
private:
virtual ConstructType getConstructData(ConstructData&);
virtual CallType getCallData(CallData&);
......
......@@ -100,12 +100,12 @@ static JSValue numberConstructorMinValue(ExecState* exec, JSValue, const Identif
}
// ECMA 15.7.1
static JSObject* constructWithNumberConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec)
{
NumberObject* object = new (exec) NumberObject(exec->lexicalGlobalObject()->numberObjectStructure());
double n = args.isEmpty() ? 0 : args.at(0).toNumber(exec);
double n = exec->argumentCount() ? exec->argument(0).toNumber(exec) : 0;
object->setInternalValue(jsNumber(exec, n));
return object;
return JSValue::encode(object);
}
ConstructType NumberConstructor::getConstructData(ConstructData& constructData)
......
......@@ -69,9 +69,10 @@ static ALWAYS_INLINE JSObject* constructObject(ExecState* exec, const ArgList& a
return arg.toObject(exec);
}
static JSObject* constructWithObjectConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithObjectConstructor(ExecState* exec)
{
return constructObject(exec, args);
ArgList args(exec);
return JSValue::encode(constructObject(exec, args));
}
ConstructType ObjectConstructor::getConstructData(ConstructData& constructData)
......
......@@ -307,9 +307,10 @@ JSObject* constructRegExp(ExecState* exec, const ArgList& args)
return new (exec) RegExpObject(exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->regExpStructure(), regExp.release());
}
static JSObject* constructWithRegExpConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
{
return constructRegExp(exec, args);
ArgList args(exec);
return JSValue::encode(constructRegExp(exec, args));
}
ConstructType RegExpConstructor::getConstructData(ConstructData& constructData)
......
......@@ -66,11 +66,11 @@ StringConstructor::StringConstructor(ExecState* exec, JSGlobalObject* globalObje
}
// ECMA 15.5.2
static JSObject* constructWithStringConstructor(ExecState* exec, JSObject*, const ArgList& args)
static EncodedJSValue JSC_HOST_CALL constructWithStringConstructor(ExecState* exec)
{
if (args.isEmpty())
return new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure());
return new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure(), args.at(0).toString(exec));
if (!exec->argumentCount())
return JSValue::encode(new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure()));
return JSValue::encode(new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure(), exec->argument(0).toString(exec)));
}
ConstructType StringConstructor::getConstructData(ConstructData& constructData)
......
2010-06-04 Gavin Barraclough <barraclough@apple.com>
Reviewed by Oliver Hunt.
Bug 40187 - Change function signature of NativeConstructor to match NativeFunction
Mostly for consistency, but constructor & args arguments are redundant,
and this will help if we wish to be able to JIT calls to more constructors.
* bindings/js/JSArrayBufferConstructor.cpp:
(WebCore::constructCanvasArrayBuffer):