{
}
-Value ArrayCtor::call(ExecutionContext *ctx)
+Value ArrayCtor::construct(ExecutionContext *ctx, Value *argv, int argc)
{
ArrayObject *a = ctx->engine->newArrayObject(ctx);
uint len;
- if (ctx->argumentCount == 1 && ctx->argument(0).isNumber()) {
+ if (argc == 1 && argv[0].isNumber()) {
bool ok;
- len = ctx->argument(0).asArrayLength(ctx, &ok);
+ len = argv[0].asArrayLength(ctx, &ok);
- if (!ok) {
- ctx->throwRangeError(ctx->argument(0));
- return Value::undefinedValue();
- }
+ if (!ok)
+ ctx->throwRangeError(argv[0]);
if (len < 0x1000)
a->arrayReserve(len);
} else {
- len = ctx->argumentCount;
+ len = argc;
a->arrayReserve(len);
for (unsigned int i = 0; i < len; ++i)
- fillDescriptor(a->arrayData + i, ctx->argument(i));
+ fillDescriptor(a->arrayData + i, argv[i]);
a->arrayDataLen = len;
}
a->setArrayLengthUnchecked(len);
return Value::fromObject(a);
}
+Value ArrayCtor::call(ExecutionContext *ctx, Value thisObject, Value *argv, int argc)
+{
+ return construct(ctx, argv, argc);
+}
+
void ArrayPrototype::init(ExecutionContext *ctx, const Value &ctor)
{
ctor.objectValue()->defineReadonlyProperty(ctx->engine->id_length, Value::fromInt32(1));
{
ArrayCtor(ExecutionContext *scope);
- virtual Value call(ExecutionContext *ctx);
+ virtual Value construct(ExecutionContext *ctx, Value *argv, int argc);
+ virtual Value call(ExecutionContext *ctx, Value thisObject, Value *argv, int argc);
};
struct ArrayPrototype: ArrayObject
return false;
}
-Value FunctionObject::construct(ExecutionContext *context, Value *args, int argc)
+Value FunctionObject::construct(ExecutionContext *context, Value *, int)
{
Object *obj = context->engine->newObject();
Value proto = __get__(context, context->engine->id_prototype);
if (proto.isObject())
obj->prototype = proto.objectValue();
-
- uint size = requiredMemoryForExecutionContect(this, argc);
- ExecutionContext *ctx = static_cast<ExecutionContext *>(needsActivation ? malloc(size) : alloca(size));
-
- ctx->thisObject = Value::fromObject(obj);
- ctx->function = this;
- ctx->arguments = args;
- ctx->argumentCount = argc;
-
- ctx->initCallContext(context);
- Value result = call(ctx);
- ctx->leaveCallContext();
-
- if (result.isObject())
- return result;
return Value::fromObject(obj);
}
{
}
+Value ScriptFunction::construct(ExecutionContext *context, Value *args, int argc)
+{
+ Object *obj = context->engine->newObject();
+ Value proto = __get__(context, context->engine->id_prototype);
+ if (proto.isObject())
+ obj->prototype = proto.objectValue();
+
+ uint size = requiredMemoryForExecutionContect(this, argc);
+ ExecutionContext *ctx = static_cast<ExecutionContext *>(needsActivation ? malloc(size) : alloca(size));
+
+ ctx->thisObject = Value::fromObject(obj);
+ ctx->function = this;
+ ctx->arguments = args;
+ ctx->argumentCount = argc;
+
+ ctx->initCallContext(context);
+ Value result = call(ctx);
+ ctx->leaveCallContext();
+
+ if (result.isObject())
+ return result;
+ return Value::fromObject(obj);
+}
+
+
+
Value ScriptFunction::call(ExecutionContext *ctx)
{
assert(function->code);
ScriptFunction(ExecutionContext *scope, VM::Function *function);
virtual ~ScriptFunction();
+ virtual Value construct(ExecutionContext *context, Value *args, int argc);
virtual Value call(ExecutionContext *ctx);
virtual ScriptFunction *asScriptFunction() { return this; }