/* static */ ArgumentsObject * ArgumentsObject::create(JSContext *cx, HandleScript script, HandleFunction callee, unsigned numActuals, CopyArgs ©) { RootedObject proto(cx, callee->global().getOrCreateObjectPrototype(cx)); if (!proto) return NULL; bool strict = callee->strict(); Class *clasp = strict ? &StrictArgumentsObjectClass : &NormalArgumentsObjectClass; RootedTypeObject type(cx, proto->getNewType(cx, clasp)); if (!type) return NULL; RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp, TaggedProto(proto), proto->getParent(), FINALIZE_KIND, BaseShape::INDEXED)); if (!shape) return NULL; unsigned numFormals = callee->nargs; unsigned numDeletedWords = NumWordsForBitArrayOfLength(numActuals); unsigned numArgs = Max(numActuals, numFormals); unsigned numBytes = offsetof(ArgumentsData, args) + numDeletedWords * sizeof(size_t) + numArgs * sizeof(Value); ArgumentsData *data = (ArgumentsData *)cx->malloc_(numBytes); if (!data) return NULL; data->numArgs = numArgs; data->callee.init(ObjectValue(*callee.get())); data->script = script; /* Copy [0, numArgs) into data->slots. */ HeapValue *dst = data->args, *dstEnd = data->args + numArgs; copy.copyArgs(cx, dst); data->deletedBits = reinterpret_cast<size_t *>(dstEnd); ClearAllBitArrayElements(data->deletedBits, numDeletedWords); RawObject obj = JSObject::create(cx, FINALIZE_KIND, GetInitialHeap(GenericObject, clasp), shape, type); if (!obj) { js_free(data); return NULL; } obj->initFixedSlot(INITIAL_LENGTH_SLOT, Int32Value(numActuals << PACKED_BITS_COUNT)); obj->initFixedSlot(DATA_SLOT, PrivateValue(data)); copy.maybeForwardToCallObject(obj, data); ArgumentsObject &argsobj = obj->asArguments(); JS_ASSERT(argsobj.initialLength() == numActuals); JS_ASSERT(!argsobj.hasOverriddenLength()); return &argsobj; }
void ArgumentsObject::trace(JSTracer *trc, RawObject obj) { ArgumentsObject &argsobj = obj->asArguments(); ArgumentsData *data = argsobj.data(); MarkValue(trc, &data->callee, js_callee_str); MarkValueRange(trc, data->numArgs, data->args, js_arguments_str); MarkScriptUnbarriered(trc, &data->script, "script"); }
void ArgumentsObject::finalize(FreeOp *fop, RawObject obj) { fop->free_(reinterpret_cast<void *>(obj->asArguments().data())); }