static bool GCZeal(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (args.length() > 2) { RootedObject callee(cx, &args.callee()); ReportUsageError(cx, callee, "Too many arguments"); return false; } uint32_t zeal; if (!ToUint32(cx, args.get(0), &zeal)) return false; uint32_t frequency = JS_DEFAULT_ZEAL_FREQ; if (args.length() >= 2) { if (!ToUint32(cx, args.get(1), &frequency)) return false; } JS_SetGCZeal(cx, (uint8_t)zeal, frequency); args.rval().setUndefined(); return true; }
// Async Iteration proposal 8.3.10 Runtime Semantics: EvaluateBody. static bool WrappedAsyncGenerator(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedFunction wrapped(cx, &args.callee().as<JSFunction>()); RootedValue unwrappedVal(cx, wrapped->getExtendedSlot(WRAPPED_ASYNC_UNWRAPPED_SLOT)); RootedFunction unwrapped(cx, &unwrappedVal.toObject().as<JSFunction>()); RootedValue thisValue(cx, args.thisv()); // Step 1. RootedValue generatorVal(cx); InvokeArgs args2(cx); if (!args2.init(cx, argc)) return false; for (size_t i = 0, len = argc; i < len; i++) args2[i].set(args[i]); if (!Call(cx, unwrappedVal, thisValue, args2, &generatorVal)) return false; // Step 2. Rooted<AsyncGeneratorObject*> asyncGenObj( cx, AsyncGeneratorObject::create(cx, wrapped, generatorVal)); if (!asyncGenObj) return false; // Step 3 (skipped). // Done in AsyncGeneratorObject::create and generator. // Step 4. args.rval().setObject(*asyncGenObj); return true; }
bool CrossCompartmentWrapper::nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs srcArgs) { JS_ASSERT_IF(!srcArgs.calleev().isUndefined(), srcArgs.callee().toFunction()->native() == native || srcArgs.callee().toFunction()->native() == js_generic_native_method_dispatcher); JS_ASSERT(srcArgs.thisv().isMagic(JS_IS_CONSTRUCTING) || &srcArgs.thisv().toObject() == wrapper); JS_ASSERT(!UnwrapObject(wrapper)->isCrossCompartmentWrapper()); JSObject *wrapped = wrappedObject(wrapper); AutoCompartment call(cx, wrapped); if (!call.enter()) return false; InvokeArgsGuard dstArgs; if (!cx->stack.pushInvokeArgs(cx, srcArgs.length(), &dstArgs)) return false; Value *src = srcArgs.base(); Value *srcend = srcArgs.array() + srcArgs.length(); Value *dst = dstArgs.base(); for (; src != srcend; ++src, ++dst) { *dst = *src; if (!call.destination->wrap(cx, dst)) return false; } if (!CallJSNative(cx, native, dstArgs)) return false; srcArgs.rval() = dstArgs.rval(); dstArgs.pop(); call.leave(); return cx->compartment->wrap(cx, &srcArgs.rval()); }
static bool ScheduleGC(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (argc != 1) { RootedObject callee(cx, &args.callee()); ReportUsageError(cx, callee, "Wrong number of arguments"); return false; } if (args[0].isInt32()) { /* Schedule a GC to happen after |arg| allocations. */ JS_ScheduleGC(cx, args[0].toInt32()); } else if (args[0].isObject()) { /* Ensure that |zone| is collected during the next GC. */ Zone *zone = UncheckedUnwrap(&args[0].toObject())->zone(); PrepareZoneForGC(zone); } else if (args[0].isString()) { /* This allows us to schedule atomsCompartment for GC. */ PrepareZoneForGC(args[0].toString()->zone()); } args.rval().setUndefined(); return true; }
void stubs::UncachedCallHelper(VMFrame &f, uint32 argc, UncachedCallResult *ucr) { ucr->init(); JSContext *cx = f.cx; CallArgs args = CallArgsFromSp(argc, f.regs.sp); if (IsFunctionObject(args.calleev(), &ucr->callee)) { ucr->callee = &args.callee(); ucr->fun = GET_FUNCTION_PRIVATE(cx, ucr->callee); if (ucr->fun->isInterpreted()) { if (!UncachedInlineCall(f, NO_CONSTRUCT, &ucr->codeAddr, &ucr->unjittable, argc)) THROW(); return; } if (ucr->fun->isNative()) { if (!CallJSNative(cx, ucr->fun->u.n.native, args)) THROW(); return; } } if (!Invoke(f.cx, args)) THROW(); return; }
static bool Error(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); /* Compute the error message, if any. */ RootedString message(cx, nullptr); if (args.hasDefined(0)) { message = ToString<CanGC>(cx, args[0]); if (!message) return false; } /* Find the scripted caller. */ NonBuiltinScriptFrameIter iter(cx); /* Set the 'fileName' property. */ RootedScript script(cx, iter.done() ? nullptr : iter.script()); RootedString fileName(cx); if (args.length() > 1) { fileName = ToString<CanGC>(cx, args[1]); } else { fileName = cx->runtime()->emptyString; if (!iter.done()) { if (const char *cfilename = script->filename()) fileName = JS_NewStringCopyZ(cx, cfilename); } } if (!fileName) return false; /* Set the 'lineNumber' property. */ uint32_t lineNumber, columnNumber = 0; if (args.length() > 2) { if (!ToUint32(cx, args[2], &lineNumber)) return false; } else { lineNumber = iter.done() ? 0 : PCToLineNumber(script, iter.pc(), &columnNumber); } Rooted<JSString*> stack(cx, ComputeStackString(cx)); if (!stack) return false; /* * ECMA ed. 3, 15.11.1 requires Error, etc., to construct even when * called as functions, without operator new. But as we do not give * each constructor a distinct JSClass, we must get the exception type * ourselves. */ JSExnType exnType = JSExnType(args.callee().as<JSFunction>().getExtendedSlot(0).toInt32()); RootedObject obj(cx, ErrorObject::create(cx, exnType, stack, fileName, lineNumber, columnNumber, nullptr, message)); if (!obj) return false; args.rval().setObject(*obj); return true; }
static bool NondeterministicGetWeakMapKeys(JSContext *cx, unsigned argc, jsval *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (argc != 1) { RootedObject callee(cx, &args.callee()); ReportUsageError(cx, callee, "Wrong number of arguments"); return false; } if (!args[0].isObject()) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_EXPECTED_TYPE, "nondeterministicGetWeakMapKeys", "WeakMap", InformalValueTypeName(args[0])); return false; } RootedObject arr(cx); if (!JS_NondeterministicGetWeakMapKeys(cx, &args[0].toObject(), arr.address())) return false; if (!arr) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_EXPECTED_TYPE, "nondeterministicGetWeakMapKeys", "WeakMap", args[0].toObject().getClass()->name); return false; } args.rval().setObject(*arr); return true; }
bool CrossCompartmentWrapper::nativeCall(JSContext *cx, JSObject *wrapper, Class *clasp, Native native, CallArgs srcArgs) { JS_ASSERT_IF(!srcArgs.calleev().isUndefined(), srcArgs.callee().getFunctionPrivate()->native() == native); JS_ASSERT(&srcArgs.thisv().toObject() == wrapper); JS_ASSERT(!UnwrapObject(wrapper)->isCrossCompartmentWrapper()); JSObject *wrapped = wrappedObject(wrapper); AutoCompartment call(cx, wrapped); if (!call.enter()) return false; InvokeArgsGuard dstArgs; if (!cx->stack.pushInvokeArgs(cx, srcArgs.length(), &dstArgs)) return false; Value *src = srcArgs.base(); Value *srcend = srcArgs.array() + srcArgs.length(); Value *dst = dstArgs.base(); for (; src != srcend; ++src, ++dst) { *dst = *src; if (!call.destination->wrap(cx, dst)) return false; } if (!Wrapper::nativeCall(cx, wrapper, clasp, native, dstArgs)) return false; dstArgs.pop(); call.leave(); srcArgs.rval() = dstArgs.rval(); return call.origin->wrap(cx, &srcArgs.rval()); }
bool SimdTypeDescr::call(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); Rooted<SimdTypeDescr*> descr(cx, &args.callee().as<SimdTypeDescr>()); MOZ_ASSERT(size_t(static_cast<TypeDescr*>(descr)->size()) <= InlineTypedObject::MaximumSize, "inline storage is needed for using InternalHandle belows"); Rooted<TypedObject*> result(cx, TypedObject::createZeroed(cx, descr, 0)); if (!result) return false; switch (descr->type()) { case SimdTypeDescr::Int8x16: return FillLanes< ::Int8x16>(cx, result, args); case SimdTypeDescr::Int16x8: return FillLanes< ::Int16x8>(cx, result, args); case SimdTypeDescr::Int32x4: return FillLanes< ::Int32x4>(cx, result, args); case SimdTypeDescr::Uint8x16: return FillLanes< ::Uint8x16>(cx, result, args); case SimdTypeDescr::Uint16x8: return FillLanes< ::Uint16x8>(cx, result, args); case SimdTypeDescr::Uint32x4: return FillLanes< ::Uint32x4>(cx, result, args); case SimdTypeDescr::Float32x4: return FillLanes< ::Float32x4>(cx, result, args); case SimdTypeDescr::Float64x2: return FillLanes< ::Float64x2>(cx, result, args); case SimdTypeDescr::Bool8x16: return FillLanes< ::Bool8x16>(cx, result, args); case SimdTypeDescr::Bool16x8: return FillLanes< ::Bool16x8>(cx, result, args); case SimdTypeDescr::Bool32x4: return FillLanes< ::Bool32x4>(cx, result, args); case SimdTypeDescr::Bool64x2: return FillLanes< ::Bool64x2>(cx, result, args); } MOZ_CRASH("unexpected SIMD descriptor"); return false; }
static JSBool ScheduleGC(JSContext *cx, unsigned argc, jsval *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (argc != 1) { RootedObject callee(cx, &args.callee()); ReportUsageError(cx, callee, "Wrong number of arguments"); return JS_FALSE; } if (args[0].isInt32()) { /* Schedule a GC to happen after |arg| allocations. */ JS_ScheduleGC(cx, args[0].toInt32()); } else if (args[0].isObject()) { /* Ensure that |zone| is collected during the next GC. */ Zone *zone = UnwrapObject(&args[0].toObject())->zone(); PrepareZoneForGC(zone); } else if (args[0].isString()) { /* This allows us to schedule atomsCompartment for GC. */ PrepareZoneForGC(args[0].toString()->zone()); } *vp = JSVAL_VOID; return JS_TRUE; }
static JSBool GCState(JSContext *cx, unsigned argc, jsval *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (argc != 0) { RootedObject callee(cx, &args.callee()); ReportUsageError(cx, callee, "Too many arguments"); return false; } const char *state; gc::State globalState = cx->runtime->gcIncrementalState; if (globalState == gc::NO_INCREMENTAL) state = "none"; else if (globalState == gc::MARK) state = "mark"; else if (globalState == gc::SWEEP) state = "sweep"; else JS_NOT_REACHED("Unobserveable global GC state"); JSString *str = JS_NewStringCopyZ(cx, state); if (!str) return false; *vp = StringValue(str); return true; }
static inline bool MaybeCloneAndPatchCallee(JSContext *cx, CallArgs args, HandleScript script, jsbytecode *pc) { if (cx->typeInferenceEnabled() && !args.calleev().isPrimitive() && args.callee().isFunction() && args.callee().toFunction()->hasScript() && args.callee().toFunction()->nonLazyScript()->shouldCloneAtCallsite) { RootedFunction fun(cx, args.callee().toFunction()); fun = CloneFunctionAtCallsite(cx, fun, script, pc); if (!fun) return false; args.setCallee(ObjectValue(*fun)); } return true; }
static bool WasmEval(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedObject callee(cx, &args.callee()); if (args.length() < 1 || args.length() > 2) { ReportUsageError(cx, callee, "Wrong number of arguments"); return false; } if (!args[0].isObject() || !args[0].toObject().is<ArrayBufferObject>()) { ReportUsageError(cx, callee, "First argument must be an ArrayBuffer"); return false; } RootedObject importObj(cx); if (!args.get(1).isUndefined()) { if (!args.get(1).isObject()) { ReportUsageError(cx, callee, "Second argument, if present, must be an Object"); return false; } importObj = &args[1].toObject(); } Rooted<ArrayBufferObject*> code(cx, &args[0].toObject().as<ArrayBufferObject>()); RootedObject exportObj(cx); if (!Eval(cx, code, importObj, &exportObj)) return false; args.rval().setObject(*exportObj); return true; }
JSBool MJitChunkLimit(JSContext *cx, unsigned argc, jsval *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (argc != 1) { RootedObject callee(cx, &args.callee()); ReportUsageError(cx, callee, "Wrong number of arguments"); return JS_FALSE; } if (cx->runtime->alwaysPreserveCode) { JS_ReportError(cx, "Can't change chunk limit after gcPreserveCode()"); return JS_FALSE; } double t; if (!JS_ValueToNumber(cx, args[0], &t)) return JS_FALSE; #ifdef JS_METHODJIT mjit::SetChunkLimit((uint32_t) t); #endif // Clear out analysis information which might refer to code compiled with // the previous chunk limit. JS_GC(cx->runtime); vp->setUndefined(); return true; }
bool js::IndirectEval(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); Rooted<GlobalObject*> global(cx, &args.callee().global()); return EvalKernel(cx, args, INDIRECT_EVAL, NullFramePtr(), global, nullptr); }
bool js::proxy_Construct(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedObject proxy(cx, &args.callee()); MOZ_ASSERT(proxy->is<ProxyObject>()); return Proxy::construct(cx, proxy, args); }
/* * Forwards the call to the exported function. Clones all the non reflectors, ignores * the |this| argument. */ static bool CloningFunctionForwarder(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); // Grab the options from the reserved slot. RootedObject optionsObj(cx, &js::GetFunctionNativeReserved(&args.callee(), 1).toObject()); FunctionForwarderOptions options(cx, optionsObj); if (!options.Parse()) return false; // Grab and unwrap the underlying callable. RootedObject forwarderObj(cx, &js::GetFunctionNativeReserved(&args.callee(), 0).toObject()); RootedObject origFunObj(cx, UncheckedUnwrap(forwarderObj)); { JSAutoCompartment ac(cx, origFunObj); // Note: only the arguments are cloned not the |this| or the |callee|. // Function forwarder does not use those. StackScopedCloneOptions cloneOptions; cloneOptions.wrapReflectors = true; for (unsigned i = 0; i < args.length(); i++) { RootedObject argObj(cx, args[i].isObject() ? &args[i].toObject() : nullptr); if (options.allowCallbacks && argObj && JS_ObjectIsCallable(cx, argObj)) { FunctionForwarderOptions innerOptions(cx); if (!JS_WrapObject(cx, &argObj)) return false; if (!xpc::NewFunctionForwarder(cx, JSID_VOIDHANDLE, argObj, innerOptions, args[i])) return false; } else if (!StackScopedClone(cx, cloneOptions, args[i])) { return false; } } // JS API does not support any JSObject to JSFunction conversion, // so let's use JS_CallFunctionValue instead. RootedValue functionVal(cx, ObjectValue(*origFunObj)); if (!JS_CallFunctionValue(cx, JS::NullPtr(), functionVal, args, args.rval())) return false; } // Return value must be wrapped. return JS_WrapValue(cx, args.rval()); }
// Implements the semantics of an asm.js module function that has been successfully validated. static bool LinkAsmJS(JSContext *cx, unsigned argc, JS::Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); // The LinkAsmJS builtin (created by NewAsmJSModuleFunction) is an extended // function and stores its module in an extended slot. RootedFunction fun(cx, &args.callee().as<JSFunction>()); Rooted<AsmJSModuleObject*> moduleObj(cx, &ModuleFunctionToModuleObject(fun)); // All ICache flushing of the module being linked has been inhibited under the // assumption that the module is flushed after dynamic linking (when the last code // mutation occurs). Thus, enter an AutoFlushICache context for the entire module // now. The module range is set below. AutoFlushICache afc("LinkAsmJS"); // When a module is linked, it is dynamically specialized to the given // arguments (buffer, ffis). Thus, if the module is linked again (it is just // a function so it can be called multiple times), we need to clone a new // module. if (moduleObj->module().isDynamicallyLinked()) { if (!CloneModule(cx, &moduleObj)) return false; } else { // CloneModule already calls setAutoFlushICacheRange internally before patching // the cloned module, so avoid calling twice. moduleObj->module().setAutoFlushICacheRange(); } AsmJSModule &module = moduleObj->module(); // Link the module by performing the link-time validation checks in the // asm.js spec and then patching the generated module to associate it with // the given heap (ArrayBuffer) and a new global data segment (the closure // state shared by the inner asm.js functions). if (!DynamicallyLinkModule(cx, args, module)) { // Linking failed, so reparse the entire asm.js module from scratch to // get normal interpreted bytecode which we can simply Invoke. Very slow. RootedPropertyName name(cx, fun->name()); return HandleDynamicLinkFailure(cx, args, module, name); } // Notify profilers so that asm.js generated code shows up with JS function // names and lines in native (i.e., not SPS) profilers. if (!SendModuleToAttachedProfiler(cx, module)) return false; // Link-time validation succeeded, so wrap all the exported functions with // CallAsmJS builtins that trampoline into the generated code. JSObject *obj = CreateExportObject(cx, moduleObj); if (!obj) return false; args.rval().set(ObjectValue(*obj)); return true; }
JSBool js::IndirectEval(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (!WarnOnTooManyArgs(cx, args)) return false; Rooted<GlobalObject*> global(cx, &args.callee().global()); return EvalKernel(cx, args, INDIRECT_EVAL, NullFramePtr(), global); }
bool ContextStack::pushInvokeFrame(JSContext *cx, const CallArgs &args, InitialFrameFlags initial, InvokeFrameGuard *ifg) { JSObject &callee = args.callee(); JSFunction *fun = callee.toFunction(); if (!pushInvokeFrame(cx, REPORT_ERROR, args, fun, initial, ifg)) return false; return true; }
static bool WasmCall(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedFunction callee(cx, &args.callee().as<JSFunction>()); Module& module = ExportedFunctionToModuleObject(callee)->module(); uint32_t exportIndex = ExportedFunctionToIndex(callee); return module.callExport(cx, exportIndex, args); }
JSBool js::LinkAsmJS(JSContext *cx, unsigned argc, JS::Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedFunction fun(cx, &args.callee().as<JSFunction>()); RootedObject moduleObj(cx, &AsmJSModuleObject(fun)); AsmJSModule &module = AsmJSModuleObjectToModule(moduleObj); // If linking fails, recompile the function (including emitting bytecode) // as if it's normal JS code. if (!DynamicallyLinkModule(cx, args, module)) { RootedPropertyName name(cx, fun->name()); return HandleDynamicLinkFailure(cx, args, module, name); } #if defined(MOZ_VTUNE) if (!SendFunctionsToVTune(cx, module)) return false; #endif if (module.numExportedFunctions() == 1) { const AsmJSModule::ExportedFunction &func = module.exportedFunction(0); if (!func.maybeFieldName()) { RootedFunction fun(cx, NewExportedFunction(cx, func, moduleObj, 0)); if (!fun) return false; args.rval().set(ObjectValue(*fun)); return true; } } gc::AllocKind allocKind = gc::GetGCObjectKind(module.numExportedFunctions()); RootedObject obj(cx, NewBuiltinClassInstance(cx, &ObjectClass, allocKind)); if (!obj) return false; for (unsigned i = 0; i < module.numExportedFunctions(); i++) { const AsmJSModule::ExportedFunction &func = module.exportedFunction(i); RootedFunction fun(cx, NewExportedFunction(cx, func, moduleObj, i)); if (!fun) return false; JS_ASSERT(func.maybeFieldName() != NULL); RootedId id(cx, NameToId(func.maybeFieldName())); RootedValue val(cx, ObjectValue(*fun)); if (!DefineNativeProperty(cx, obj, id, val, NULL, NULL, JSPROP_ENUMERATE, 0, 0)) return false; } args.rval().set(ObjectValue(*obj)); return true; }
static bool WasmCall(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedFunction callee(cx, &args.callee().as<JSFunction>()); Instance& instance = ExportedFunctionToInstance(callee); uint32_t funcExportIndex = ExportedFunctionToExportIndex(callee); return instance.callExport(cx, funcExportIndex, args); }
bool X4Type::call(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); const uint32_t LANES = 4; if (args.length() < LANES) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED, args.callee().getClass()->name, "3", "s"); return false; } double values[LANES]; for (uint32_t i = 0; i < LANES; i++) { if (!ToNumber(cx, args[i], &values[i])) return false; } RootedObject typeObj(cx, &args.callee()); Rooted<TypedObject*> result(cx, TypedObject::createZeroed(cx, typeObj, 0)); if (!result) return false; X4TypeRepresentation *typeRepr = typeRepresentation(*typeObj)->asX4(); switch (typeRepr->type()) { #define STORE_LANES(_constant, _type, _name) \ case _constant: \ { \ _type *mem = reinterpret_cast<_type*>(result->typedMem()); \ for (uint32_t i = 0; i < LANES; i++) { \ mem[i] = ConvertScalar<_type>(values[i]); \ } \ break; \ } JS_FOR_EACH_X4_TYPE_REPR(STORE_LANES) #undef STORE_LANES } args.rval().setObject(*result); return true; }
bool X4TypeDescr::call(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); const unsigned LANES = 4; if (args.length() < LANES) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED, args.callee().getClass()->name, "3", "s"); return false; } double values[LANES]; for (unsigned i = 0; i < LANES; i++) { if (!ToNumber(cx, args[i], &values[i])) return false; } Rooted<X4TypeDescr*> descr(cx, &args.callee().as<X4TypeDescr>()); Rooted<TypedObject*> result(cx, TypedObject::createZeroed(cx, descr, 0)); if (!result) return false; MOZ_ASSERT(!result->owner().isNeutered()); switch (descr->type()) { #define STORE_LANES(_constant, _type, _name) \ case _constant: \ { \ _type *mem = reinterpret_cast<_type*>(result->typedMem()); \ for (unsigned i = 0; i < LANES; i++) \ mem[i] = ConvertScalar<_type>(values[i]); \ break; \ } JS_FOR_EACH_X4_TYPE_REPR(STORE_LANES) #undef STORE_LANES } args.rval().setObject(*result); return true; }
bool js::IndirectEval(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); Rooted<GlobalObject*> global(cx, &args.callee().global()); RootedObject globalLexical(cx, &global->lexicalScope()); // Note we'll just pass |undefined| here, then return it directly (or throw // if runtime codegen is disabled), if no argument is provided. return EvalKernel(cx, args.get(0), INDIRECT_EVAL, NullFramePtr(), globalLexical, nullptr, args.rval()); }
static JSBool VerifyPreBarriers(JSContext *cx, unsigned argc, jsval *vp) { CallArgs args = CallArgsFromVp(argc, vp); if (argc) { RootedObject callee(cx, &args.callee()); ReportUsageError(cx, callee, "Too many arguments"); return JS_FALSE; } gc::VerifyBarriers(cx->runtime, gc::PreBarrierVerifier); *vp = JSVAL_VOID; return JS_TRUE; }
bool SimdTypeDescr::call(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); Rooted<SimdTypeDescr*> descr(cx, &args.callee().as<SimdTypeDescr>()); if (args.length() == 1) { // SIMD type used as a coercion if (!CheckVectorObject(args[0], descr->type())) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_SIMD_NOT_A_VECTOR); return false; } args.rval().setObject(args[0].toObject()); return true; } Rooted<TypedObject*> result(cx, TypedObject::createZeroed(cx, descr, 0)); if (!result) return false; switch (descr->type()) { case SimdTypeDescr::TYPE_INT32: { int32_t *mem = reinterpret_cast<int32_t*>(result->typedMem()); for (unsigned i = 0; i < 4; i++) { if (!ToInt32(cx, args.get(i), &mem[i])) return false; } break; } case SimdTypeDescr::TYPE_FLOAT32: { float *mem = reinterpret_cast<float*>(result->typedMem()); for (unsigned i = 0; i < 4; i++) { if (!RoundFloat32(cx, args.get(i), &mem[i])) return false; } break; } case SimdTypeDescr::TYPE_FLOAT64: { double *mem = reinterpret_cast<double*>(result->typedMem()); for (unsigned i = 0; i < 2; i++) { if (!ToNumber(cx, args.get(i), &mem[i])) return false; } break; } } args.rval().setObject(*result); return true; }
static bool ProtoSetter(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); // Do this here, rather than in |ProtoSetterImpl|, so even likely-buggy // use of the __proto__ setter on unacceptable values, where no subsequent // use occurs on an acceptable value, will trigger a warning. RootedObject callee(cx, &args.callee()); if (!GlobalObject::warnOnceAboutPrototypeMutation(cx, callee)) return false; return CallNonGenericMethod(cx, TestProtoThis, ProtoSetterImpl, args); }
static bool NonCloningFunctionForwarder(JSContext *cx, unsigned argc, Value *vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedValue v(cx, js::GetFunctionNativeReserved(&args.callee(), 0)); MOZ_ASSERT(v.isObject(), "weird function"); RootedObject obj(cx, JS_THIS_OBJECT(cx, vp)); if (!obj) { return false; } return JS_CallFunctionValue(cx, obj, v, args, args.rval()); }