Bug 949747 - Use accessor methods for JSFunction fields, r=jandem.

This commit is contained in:
Brian Hackett 2013-12-14 16:38:07 -08:00
Родитель 3f5d9fdd14
Коммит ecb06a8b95
36 изменённых файлов: 160 добавлений и 136 удалений

Просмотреть файл

@ -847,7 +847,7 @@ Parser<FullParseHandler>::standaloneFunctionBody(HandleFunction fun, const AutoN
generatorKind); generatorKind);
if (!funbox) if (!funbox)
return null(); return null();
funbox->length = fun->nargs - fun->hasRest(); funbox->length = fun->nargs() - fun->hasRest();
handler.setFunctionBox(fn, funbox); handler.setFunctionBox(fn, funbox);
ParseContext<FullParseHandler> funpc(this, pc, fn, funbox, newDirectives, ParseContext<FullParseHandler> funpc(this, pc, fn, funbox, newDirectives,
@ -2212,7 +2212,7 @@ Parser<FullParseHandler>::standaloneLazyFunction(HandleFunction fun, unsigned st
generatorKind); generatorKind);
if (!funbox) if (!funbox)
return null(); return null();
funbox->length = fun->nargs - fun->hasRest(); funbox->length = fun->nargs() - fun->hasRest();
Directives newDirectives = directives; Directives newDirectives = directives;
ParseContext<FullParseHandler> funpc(this, /* parent = */ nullptr, pn, funbox, ParseContext<FullParseHandler> funpc(this, /* parent = */ nullptr, pn, funbox,
@ -2265,11 +2265,11 @@ Parser<ParseHandler>::functionArgsAndBodyGeneric(Node pn, HandleFunction fun, Fu
if (hasRest) if (hasRest)
fun->setHasRest(); fun->setHasRest();
if (type == Getter && fun->nargs > 0) { if (type == Getter && fun->nargs() > 0) {
report(ParseError, false, null(), JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s"); report(ParseError, false, null(), JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s");
return false; return false;
} }
if (type == Setter && fun->nargs != 1) { if (type == Setter && fun->nargs() != 1) {
report(ParseError, false, null(), JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", ""); report(ParseError, false, null(), JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", "");
return false; return false;
} }

Просмотреть файл

@ -289,7 +289,7 @@ class FunctionBox : public ObjectBox, public SharedContext
funCxFlags.definitelyNeedsArgsObj = true; } funCxFlags.definitelyNeedsArgsObj = true; }
bool hasDefaults() const { bool hasDefaults() const {
return length != function()->nargs - function()->hasRest(); return length != function()->nargs() - function()->hasRest();
} }
// Return whether this function has either specified "use asm" or is // Return whether this function has either specified "use asm" or is

Просмотреть файл

@ -5967,14 +5967,14 @@ TryEnablingIon(JSContext *cx, AsmJSModule &module, HandleFunction fun, uint32_t
return true; return true;
// Currently we can't rectify arguments. Therefore disabling if argc is too low. // Currently we can't rectify arguments. Therefore disabling if argc is too low.
if (fun->nargs > argc) if (fun->nargs() > size_t(argc))
return true; return true;
// Normally the types should corresond, since we just ran with those types, // Normally the types should corresond, since we just ran with those types,
// but there are reports this is asserting. Therefore doing it as a check, instead of DEBUG only. // but there are reports this is asserting. Therefore doing it as a check, instead of DEBUG only.
if (!types::TypeScript::ThisTypes(script)->hasType(types::Type::UndefinedType())) if (!types::TypeScript::ThisTypes(script)->hasType(types::Type::UndefinedType()))
return true; return true;
for(uint32_t i = 0; i < fun->nargs; i++) { for(uint32_t i = 0; i < fun->nargs(); i++) {
types::StackTypeSet *typeset = types::TypeScript::ArgTypes(script, i); types::StackTypeSet *typeset = types::TypeScript::ArgTypes(script, i);
types::Type type = types::Type::DoubleType(); types::Type type = types::Type::DoubleType();
if (!argv[i].isDouble()) if (!argv[i].isDouble())

Просмотреть файл

@ -682,7 +682,7 @@ JSFunction *
js::NewAsmJSModuleFunction(ExclusiveContext *cx, JSFunction *origFun, HandleObject moduleObj) js::NewAsmJSModuleFunction(ExclusiveContext *cx, JSFunction *origFun, HandleObject moduleObj)
{ {
RootedPropertyName name(cx, origFun->name()); RootedPropertyName name(cx, origFun->name());
JSFunction *moduleFun = NewFunction(cx, NullPtr(), LinkAsmJS, origFun->nargs, JSFunction *moduleFun = NewFunction(cx, NullPtr(), LinkAsmJS, origFun->nargs(),
JSFunction::NATIVE_FUN, NullPtr(), name, JSFunction::NATIVE_FUN, NullPtr(), name,
JSFunction::ExtendedFinalizeKind, TenuredObject); JSFunction::ExtendedFinalizeKind, TenuredObject);
if (!moduleFun) if (!moduleFun)

Просмотреть файл

@ -624,7 +624,7 @@ InitFromBailout(JSContext *cx, HandleScript caller, jsbytecode *callerPC,
JS_ASSERT(iter.slots() >= CountArgSlots(script, fun)); JS_ASSERT(iter.slots() >= CountArgSlots(script, fun));
IonSpew(IonSpew_BaselineBailouts, " frame slots %u, nargs %u, nfixed %u", IonSpew(IonSpew_BaselineBailouts, " frame slots %u, nargs %u, nfixed %u",
iter.slots(), fun->nargs, script->nfixed()); iter.slots(), fun->nargs(), script->nfixed());
if (!callerPC) { if (!callerPC) {
// This is the first frame. Store the formals in a Vector until we // This is the first frame. Store the formals in a Vector until we
@ -633,11 +633,11 @@ InitFromBailout(JSContext *cx, HandleScript caller, jsbytecode *callerPC,
// locals may still reference the original argument slot // locals may still reference the original argument slot
// (MParameter/LArgument) and expect the original Value. // (MParameter/LArgument) and expect the original Value.
JS_ASSERT(startFrameFormals.empty()); JS_ASSERT(startFrameFormals.empty());
if (!startFrameFormals.resize(fun->nargs)) if (!startFrameFormals.resize(fun->nargs()))
return false; return false;
} }
for (uint32_t i = 0; i < fun->nargs; i++) { for (uint32_t i = 0; i < fun->nargs(); i++) {
Value arg = iter.read(); Value arg = iter.read();
IonSpew(IonSpew_BaselineBailouts, " arg %d = %016llx", IonSpew(IonSpew_BaselineBailouts, " arg %d = %016llx",
(int) i, *((uint64_t *) &arg)); (int) i, *((uint64_t *) &arg));
@ -1108,7 +1108,7 @@ InitFromBailout(JSContext *cx, HandleScript caller, jsbytecode *callerPC,
// If actualArgc >= fun->nargs, then we are done. Otherwise, we need to push on // If actualArgc >= fun->nargs, then we are done. Otherwise, we need to push on
// a reconstructed rectifier frame. // a reconstructed rectifier frame.
if (actualArgc >= calleeFun->nargs) if (actualArgc >= calleeFun->nargs())
return true; return true;
// Push a reconstructed rectifier frame. // Push a reconstructed rectifier frame.
@ -1147,7 +1147,7 @@ InitFromBailout(JSContext *cx, HandleScript caller, jsbytecode *callerPC,
#endif #endif
// Push undefined for missing arguments. // Push undefined for missing arguments.
for (unsigned i = 0; i < (calleeFun->nargs - actualArgc); i++) { for (unsigned i = 0; i < (calleeFun->nargs() - actualArgc); i++) {
if (!builder.writeValue(UndefinedValue(), "FillerVal")) if (!builder.writeValue(UndefinedValue(), "FillerVal"))
return false; return false;
} }

Просмотреть файл

@ -668,7 +668,7 @@ BaselineCompiler::emitArgumentTypeChecks()
if (!emitNonOpIC(compiler.getStub(&stubSpace_))) if (!emitNonOpIC(compiler.getStub(&stubSpace_)))
return false; return false;
for (size_t i = 0; i < function()->nargs; i++) { for (size_t i = 0; i < function()->nargs(); i++) {
frame.pushArg(i); frame.pushArg(i);
frame.popRegsAndSync(1); frame.popRegsAndSync(1);

Просмотреть файл

@ -182,7 +182,7 @@ class BaselineFrame
offsetOfNumActualArgs()); offsetOfNumActualArgs());
} }
unsigned numFormalArgs() const { unsigned numFormalArgs() const {
return script()->function()->nargs; return script()->function()->nargs();
} }
Value &thisValue() const { Value &thisValue() const {
return *(Value *)(reinterpret_cast<const uint8_t *>(this) + return *(Value *)(reinterpret_cast<const uint8_t *>(this) +

Просмотреть файл

@ -182,7 +182,7 @@ class FrameInfo
return script->nfixed(); return script->nfixed();
} }
uint32_t nargs() const { uint32_t nargs() const {
return script->function()->nargs; return script->function()->nargs();
} }
private: private:

Просмотреть файл

@ -4125,7 +4125,7 @@ ICGetElemNativeCompiler::emitCallScripted(MacroAssembler &masm, Register objReg)
// Handle arguments underflow. // Handle arguments underflow.
Label noUnderflow; Label noUnderflow;
masm.load16ZeroExtend(Address(callee, offsetof(JSFunction, nargs)), scratch); masm.load16ZeroExtend(Address(callee, JSFunction::offsetOfNargs()), scratch);
masm.branch32(Assembler::Equal, scratch, Imm32(0), &noUnderflow); masm.branch32(Assembler::Equal, scratch, Imm32(0), &noUnderflow);
{ {
// Call the arguments rectifier. // Call the arguments rectifier.
@ -6682,7 +6682,7 @@ ICGetProp_CallScripted::Compiler::generateStubCode(MacroAssembler &masm)
// Handle arguments underflow. // Handle arguments underflow.
Label noUnderflow; Label noUnderflow;
masm.load16ZeroExtend(Address(callee, offsetof(JSFunction, nargs)), scratch); masm.load16ZeroExtend(Address(callee, JSFunction::offsetOfNargs()), scratch);
masm.branch32(Assembler::Equal, scratch, Imm32(0), &noUnderflow); masm.branch32(Assembler::Equal, scratch, Imm32(0), &noUnderflow);
{ {
// Call the arguments rectifier. // Call the arguments rectifier.
@ -7591,7 +7591,7 @@ ICSetProp_CallScripted::Compiler::generateStubCode(MacroAssembler &masm)
// Handle arguments underflow. // Handle arguments underflow.
Label noUnderflow; Label noUnderflow;
masm.load16ZeroExtend(Address(callee, offsetof(JSFunction, nargs)), scratch); masm.load16ZeroExtend(Address(callee, JSFunction::offsetOfNargs()), scratch);
masm.branch32(Assembler::BelowOrEqual, scratch, Imm32(1), &noUnderflow); masm.branch32(Assembler::BelowOrEqual, scratch, Imm32(1), &noUnderflow);
{ {
// Call the arguments rectifier. // Call the arguments rectifier.
@ -8538,7 +8538,7 @@ ICCallScriptedCompiler::generateStubCode(MacroAssembler &masm)
// Handle arguments underflow. // Handle arguments underflow.
Label noUnderflow; Label noUnderflow;
masm.load16ZeroExtend(Address(callee, offsetof(JSFunction, nargs)), callee); masm.load16ZeroExtend(Address(callee, JSFunction::offsetOfNargs()), callee);
masm.branch32(Assembler::AboveOrEqual, argcReg, callee, &noUnderflow); masm.branch32(Assembler::AboveOrEqual, argcReg, callee, &noUnderflow);
{ {
// Call the arguments rectifier. // Call the arguments rectifier.
@ -8794,7 +8794,7 @@ ICCall_ScriptedApplyArray::Compiler::generateStubCode(MacroAssembler &masm)
masm.Push(scratch); masm.Push(scratch);
// Load nargs into scratch for underflow check, and then load jitcode pointer into target. // Load nargs into scratch for underflow check, and then load jitcode pointer into target.
masm.load16ZeroExtend(Address(target, offsetof(JSFunction, nargs)), scratch); masm.load16ZeroExtend(Address(target, JSFunction::offsetOfNargs()), scratch);
masm.loadPtr(Address(target, JSFunction::offsetOfNativeOrScript()), target); masm.loadPtr(Address(target, JSFunction::offsetOfNativeOrScript()), target);
masm.loadBaselineOrIonRaw(target, target, SequentialExecution, nullptr); masm.loadBaselineOrIonRaw(target, target, SequentialExecution, nullptr);
@ -8905,7 +8905,7 @@ ICCall_ScriptedApplyArguments::Compiler::generateStubCode(MacroAssembler &masm)
masm.Push(scratch); masm.Push(scratch);
// Load nargs into scratch for underflow check, and then load jitcode pointer into target. // Load nargs into scratch for underflow check, and then load jitcode pointer into target.
masm.load16ZeroExtend(Address(target, offsetof(JSFunction, nargs)), scratch); masm.load16ZeroExtend(Address(target, JSFunction::offsetOfNargs()), scratch);
masm.loadPtr(Address(target, JSFunction::offsetOfNativeOrScript()), target); masm.loadPtr(Address(target, JSFunction::offsetOfNativeOrScript()), target);
masm.loadBaselineOrIonRaw(target, target, SequentialExecution, nullptr); masm.loadBaselineOrIonRaw(target, target, SequentialExecution, nullptr);

Просмотреть файл

@ -826,11 +826,11 @@ CodeGenerator::emitLambdaInit(const Register &output, const Register &scopeChain
} s; } s;
uint32_t word; uint32_t word;
} u; } u;
u.s.nargs = info.fun->nargs; u.s.nargs = info.fun->nargs();
u.s.flags = info.flags & ~JSFunction::EXTENDED; u.s.flags = info.flags & ~JSFunction::EXTENDED;
JS_STATIC_ASSERT(offsetof(JSFunction, flags) == offsetof(JSFunction, nargs) + 2); JS_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2);
masm.store32(Imm32(u.word), Address(output, offsetof(JSFunction, nargs))); masm.store32(Imm32(u.word), Address(output, JSFunction::offsetOfNargs()));
masm.storePtr(ImmGCPtr(info.scriptOrLazyScript), masm.storePtr(ImmGCPtr(info.scriptOrLazyScript),
Address(output, JSFunction::offsetOfNativeOrScript())); Address(output, JSFunction::offsetOfNativeOrScript()));
masm.storePtr(scopeChain, Address(output, JSFunction::offsetOfEnvironment())); masm.storePtr(scopeChain, Address(output, JSFunction::offsetOfEnvironment()));
@ -1953,7 +1953,7 @@ CodeGenerator::visitCallGeneric(LCallGeneric *call)
masm.Push(Imm32(descriptor)); masm.Push(Imm32(descriptor));
// Check whether the provided arguments satisfy target argc. // Check whether the provided arguments satisfy target argc.
masm.load16ZeroExtend(Address(calleereg, offsetof(JSFunction, nargs)), nargsreg); masm.load16ZeroExtend(Address(calleereg, JSFunction::offsetOfNargs()), nargsreg);
masm.cmp32(nargsreg, Imm32(call->numStackArgs())); masm.cmp32(nargsreg, Imm32(call->numStackArgs()));
masm.j(Assembler::Above, &thunk); masm.j(Assembler::Above, &thunk);
@ -2045,7 +2045,7 @@ CodeGenerator::visitCallKnown(LCallKnown *call)
// Native single targets are handled by LCallNative. // Native single targets are handled by LCallNative.
JS_ASSERT(!target->isNative()); JS_ASSERT(!target->isNative());
// Missing arguments must have been explicitly appended by the IonBuilder. // Missing arguments must have been explicitly appended by the IonBuilder.
JS_ASSERT(target->nargs <= call->numStackArgs()); JS_ASSERT(target->nargs() <= call->numStackArgs());
JS_ASSERT_IF(call->mir()->isConstructing(), target->isInterpretedConstructor()); JS_ASSERT_IF(call->mir()->isConstructing(), target->isInterpretedConstructor());
@ -2285,11 +2285,11 @@ CodeGenerator::visitApplyArgsGeneric(LApplyArgsGeneric *apply)
// Check whether the provided arguments satisfy target argc. // Check whether the provided arguments satisfy target argc.
if (!apply->hasSingleTarget()) { if (!apply->hasSingleTarget()) {
masm.load16ZeroExtend(Address(calleereg, offsetof(JSFunction, nargs)), copyreg); masm.load16ZeroExtend(Address(calleereg, JSFunction::offsetOfNargs()), copyreg);
masm.cmp32(argcreg, copyreg); masm.cmp32(argcreg, copyreg);
masm.j(Assembler::Below, &underflow); masm.j(Assembler::Below, &underflow);
} else { } else {
masm.cmp32(argcreg, Imm32(apply->getSingleTarget()->nargs)); masm.cmp32(argcreg, Imm32(apply->getSingleTarget()->nargs()));
masm.j(Assembler::Below, &underflow); masm.j(Assembler::Below, &underflow);
} }

Просмотреть файл

@ -37,7 +37,7 @@ CountArgSlots(JSScript *script, JSFunction *fun)
// Slot x + n: Argument n. // Slot x + n: Argument n.
// Note: when updating this, please also update the assert in SnapshotWriter::startFrame // Note: when updating this, please also update the assert in SnapshotWriter::startFrame
return StartArgSlot(script) + (fun ? fun->nargs + 1 : 0); return StartArgSlot(script) + (fun ? fun->nargs() + 1 : 0);
} }
// Contains information about the compilation source for IR being generated. // Contains information about the compilation source for IR being generated.
@ -60,7 +60,7 @@ class CompileInfo
nimplicit_ = StartArgSlot(script) /* scope chain and argument obj */ nimplicit_ = StartArgSlot(script) /* scope chain and argument obj */
+ (fun ? 1 : 0); /* this */ + (fun ? 1 : 0); /* this */
nargs_ = fun ? fun->nargs : 0; nargs_ = fun ? fun->nargs() : 0;
nlocals_ = script->nfixed(); nlocals_ = script->nfixed();
nstack_ = script->nslots() - script->nfixed(); nstack_ = script->nslots() - script->nfixed();
nslots_ = nimplicit_ + nargs_ + nlocals_ + nstack_; nslots_ = nimplicit_ + nargs_ + nlocals_ + nstack_;

Просмотреть файл

@ -2018,7 +2018,7 @@ jit::CanEnter(JSContext *cx, RunState &state)
return Method_CantCompile; return Method_CantCompile;
} }
if (TooManyArguments(invoke.args().callee().as<JSFunction>().nargs)) { if (TooManyArguments(invoke.args().callee().as<JSFunction>().nargs())) {
IonSpew(IonSpew_Abort, "too many args"); IonSpew(IonSpew_Abort, "too many args");
ForbidCompilation(cx, script); ForbidCompilation(cx, script);
return Method_CantCompile; return Method_CantCompile;
@ -2165,7 +2165,7 @@ jit::CanEnterUsingFastInvoke(JSContext *cx, HandleScript script, uint32_t numAct
// Don't handle arguments underflow, to make this work we would have to pad // Don't handle arguments underflow, to make this work we would have to pad
// missing arguments with |undefined|. // missing arguments with |undefined|.
if (numActualArgs < script->function()->nargs) if (numActualArgs < script->function()->nargs())
return Method_Skipped; return Method_Skipped;
if (!cx->compartment()->ensureJitCompartmentExists(cx)) if (!cx->compartment()->ensureJitCompartmentExists(cx))
@ -2226,7 +2226,7 @@ jit::SetEnterJitData(JSContext *cx, EnterJitData &data, RunState &state, AutoVal
if (state.isInvoke()) { if (state.isInvoke()) {
CallArgs &args = state.asInvoke()->args(); CallArgs &args = state.asInvoke()->args();
unsigned numFormals = state.script()->function()->nargs; unsigned numFormals = state.script()->function()->nargs();
data.constructing = state.asInvoke()->constructing(); data.constructing = state.asInvoke()->constructing();
data.numActualArgs = args.length(); data.numActualArgs = args.length();
data.maxArgc = Max(args.length(), numFormals) + 1; data.maxArgc = Max(args.length(), numFormals) + 1;
@ -2309,7 +2309,7 @@ jit::FastInvoke(JSContext *cx, HandleFunction fun, CallArgs &args)
void *calleeToken = CalleeToToken(fun); void *calleeToken = CalleeToToken(fun);
RootedValue result(cx, Int32Value(args.length())); RootedValue result(cx, Int32Value(args.length()));
JS_ASSERT(args.length() >= fun->nargs); JS_ASSERT(args.length() >= fun->nargs());
JSAutoResolveFlags rf(cx, RESOLVE_INFER); JSAutoResolveFlags rf(cx, RESOLVE_INFER);
enter(jitcode, args.length() + 1, args.array() - 1, nullptr, calleeToken, enter(jitcode, args.length() + 1, args.array() - 1, nullptr, calleeToken,

Просмотреть файл

@ -361,7 +361,7 @@ IonBuilder::canInlineTarget(JSFunction *target, CallInfo &callInfo)
if (!inlineScript->hasBaselineScript()) if (!inlineScript->hasBaselineScript())
return DontInline(inlineScript, "No baseline jitcode"); return DontInline(inlineScript, "No baseline jitcode");
if (TooManyArguments(target->nargs)) if (TooManyArguments(target->nargs()))
return DontInline(inlineScript, "Too many args"); return DontInline(inlineScript, "Too many args");
if (TooManyArguments(callInfo.argc())) if (TooManyArguments(callInfo.argc()))
@ -5136,12 +5136,12 @@ IonBuilder::testNeedsArgumentCheck(JSFunction *target, CallInfo &callInfo)
if (!ArgumentTypesMatch(callInfo.thisArg(), types::TypeScript::ThisTypes(targetScript))) if (!ArgumentTypesMatch(callInfo.thisArg(), types::TypeScript::ThisTypes(targetScript)))
return true; return true;
uint32_t expected_args = Min<uint32_t>(callInfo.argc(), target->nargs); uint32_t expected_args = Min<uint32_t>(callInfo.argc(), target->nargs());
for (size_t i = 0; i < expected_args; i++) { for (size_t i = 0; i < expected_args; i++) {
if (!ArgumentTypesMatch(callInfo.getArg(i), types::TypeScript::ArgTypes(targetScript, i))) if (!ArgumentTypesMatch(callInfo.getArg(i), types::TypeScript::ArgTypes(targetScript, i)))
return true; return true;
} }
for (size_t i = callInfo.argc(); i < target->nargs; i++) { for (size_t i = callInfo.argc(); i < target->nargs(); i++) {
if (!types::TypeScript::ArgTypes(targetScript, i)->mightBeType(JSVAL_TYPE_UNDEFINED)) if (!types::TypeScript::ArgTypes(targetScript, i)->mightBeType(JSVAL_TYPE_UNDEFINED))
return true; return true;
} }
@ -5162,7 +5162,7 @@ IonBuilder::makeCallHelper(JSFunction *target, CallInfo &callInfo, bool cloneAtC
// Collect number of missing arguments provided that the target is // Collect number of missing arguments provided that the target is
// scripted. Native functions are passed an explicit 'argc' parameter. // scripted. Native functions are passed an explicit 'argc' parameter.
if (target && !target->isNative()) if (target && !target->isNative())
targetArgs = Max<uint32_t>(target->nargs, callInfo.argc()); targetArgs = Max<uint32_t>(target->nargs(), callInfo.argc());
MCall *call = MCall *call =
MCall::New(alloc(), target, targetArgs + 1, callInfo.argc(), callInfo.constructing()); MCall::New(alloc(), target, targetArgs + 1, callInfo.argc(), callInfo.constructing());

Просмотреть файл

@ -398,7 +398,7 @@ class InlineFrameIteratorMaybeGC
count = nactual - start; count = nactual - start;
unsigned end = start + count; unsigned end = start + count;
unsigned nformal = callee()->nargs; unsigned nformal = callee()->nargs();
JS_ASSERT(start <= end && end <= nactual); JS_ASSERT(start <= end && end <= nactual);

Просмотреть файл

@ -1659,15 +1659,15 @@ InlineFrameIteratorMaybeGC<allowGC>::dump() const
fprintf(stderr, " scope chain: "); fprintf(stderr, " scope chain: ");
else if (i == 1) else if (i == 1)
fprintf(stderr, " this: "); fprintf(stderr, " this: ");
else if (i - 2 < callee()->nargs) else if (i - 2 < callee()->nargs())
fprintf(stderr, " formal (arg %d): ", i - 2); fprintf(stderr, " formal (arg %d): ", i - 2);
else { else {
if (i - 2 == callee()->nargs && numActualArgs() > callee()->nargs) { if (i - 2 == callee()->nargs() && numActualArgs() > callee()->nargs()) {
DumpOp d(callee()->nargs); DumpOp d(callee()->nargs());
forEachCanonicalActualArg(GetIonContext()->cx, d, d.i_, numActualArgs() - d.i_); forEachCanonicalActualArg(GetIonContext()->cx, d, d.i_, numActualArgs() - d.i_);
} }
fprintf(stderr, " slot %d: ", i - 2 - callee()->nargs); fprintf(stderr, " slot %d: ", int(i - 2 - callee()->nargs()));
} }
} else } else
fprintf(stderr, " slot %u: ", i); fprintf(stderr, " slot %u: ", i);

Просмотреть файл

@ -1780,8 +1780,8 @@ MacroAssembler::branchIfNotInterpretedConstructor(Register fun, Register scratch
{ {
// 16-bit loads are slow and unaligned 32-bit loads may be too so // 16-bit loads are slow and unaligned 32-bit loads may be too so
// perform an aligned 32-bit load and adjust the bitmask accordingly. // perform an aligned 32-bit load and adjust the bitmask accordingly.
JS_STATIC_ASSERT(offsetof(JSFunction, nargs) % sizeof(uint32_t) == 0); JS_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0);
JS_STATIC_ASSERT(offsetof(JSFunction, flags) == offsetof(JSFunction, nargs) + 2); JS_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2);
JS_STATIC_ASSERT(IS_LITTLE_ENDIAN); JS_STATIC_ASSERT(IS_LITTLE_ENDIAN);
// Emit code for the following test: // Emit code for the following test:
@ -1792,7 +1792,7 @@ MacroAssembler::branchIfNotInterpretedConstructor(Register fun, Register scratch
// } // }
// First, ensure it's a scripted function. // First, ensure it's a scripted function.
load32(Address(fun, offsetof(JSFunction, nargs)), scratch); load32(Address(fun, JSFunction::offsetOfNargs()), scratch);
branchTest32(Assembler::Zero, scratch, Imm32(JSFunction::INTERPRETED << 16), label); branchTest32(Assembler::Zero, scratch, Imm32(JSFunction::INTERPRETED << 16), label);
// Common case: if both IS_FUN_PROTO and SELF_HOSTED are not set, // Common case: if both IS_FUN_PROTO and SELF_HOSTED are not set,

Просмотреть файл

@ -490,20 +490,20 @@ class MacroAssembler : public MacroAssemblerSpecific
void branchIfFunctionHasNoScript(Register fun, Label *label) { void branchIfFunctionHasNoScript(Register fun, Label *label) {
// 16-bit loads are slow and unaligned 32-bit loads may be too so // 16-bit loads are slow and unaligned 32-bit loads may be too so
// perform an aligned 32-bit load and adjust the bitmask accordingly. // perform an aligned 32-bit load and adjust the bitmask accordingly.
JS_STATIC_ASSERT(offsetof(JSFunction, nargs) % sizeof(uint32_t) == 0); JS_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0);
JS_STATIC_ASSERT(offsetof(JSFunction, flags) == offsetof(JSFunction, nargs) + 2); JS_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2);
JS_STATIC_ASSERT(IS_LITTLE_ENDIAN); JS_STATIC_ASSERT(IS_LITTLE_ENDIAN);
Address address(fun, offsetof(JSFunction, nargs)); Address address(fun, JSFunction::offsetOfNargs());
uint32_t bit = JSFunction::INTERPRETED << 16; uint32_t bit = JSFunction::INTERPRETED << 16;
branchTest32(Assembler::Zero, address, Imm32(bit), label); branchTest32(Assembler::Zero, address, Imm32(bit), label);
} }
void branchIfInterpreted(Register fun, Label *label) { void branchIfInterpreted(Register fun, Label *label) {
// 16-bit loads are slow and unaligned 32-bit loads may be too so // 16-bit loads are slow and unaligned 32-bit loads may be too so
// perform an aligned 32-bit load and adjust the bitmask accordingly. // perform an aligned 32-bit load and adjust the bitmask accordingly.
JS_STATIC_ASSERT(offsetof(JSFunction, nargs) % sizeof(uint32_t) == 0); JS_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0);
JS_STATIC_ASSERT(offsetof(JSFunction, flags) == offsetof(JSFunction, nargs) + 2); JS_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2);
JS_STATIC_ASSERT(IS_LITTLE_ENDIAN); JS_STATIC_ASSERT(IS_LITTLE_ENDIAN);
Address address(fun, offsetof(JSFunction, nargs)); Address address(fun, JSFunction::offsetOfNargs());
uint32_t bit = JSFunction::INTERPRETED << 16; uint32_t bit = JSFunction::INTERPRETED << 16;
branchTest32(Assembler::NonZero, address, Imm32(bit), label); branchTest32(Assembler::NonZero, address, Imm32(bit), label);
} }

Просмотреть файл

@ -4939,7 +4939,7 @@ struct LambdaFunctionInfo
bool useNewTypeForClone; bool useNewTypeForClone;
LambdaFunctionInfo(JSFunction *fun) LambdaFunctionInfo(JSFunction *fun)
: fun(fun), flags(fun->flags), : fun(fun), flags(fun->flags()),
scriptOrLazyScript(fun->hasScript() scriptOrLazyScript(fun->hasScript()
? (gc::Cell *) fun->nonLazyScript() ? (gc::Cell *) fun->nonLazyScript()
: (gc::Cell *) fun->lazyScript()), : (gc::Cell *) fun->lazyScript()),

Просмотреть файл

@ -423,7 +423,7 @@ JitRuntime::generateArgumentsRectifier(JSContext *cx, ExecutionMode mode, void *
// Load the number of |undefined|s to push into r6. // Load the number of |undefined|s to push into r6.
masm.ma_ldr(DTRAddr(sp, DtrOffImm(IonRectifierFrameLayout::offsetOfCalleeToken())), r1); masm.ma_ldr(DTRAddr(sp, DtrOffImm(IonRectifierFrameLayout::offsetOfCalleeToken())), r1);
masm.ma_ldrh(EDtrAddr(r1, EDtrOffImm(offsetof(JSFunction, nargs))), r6); masm.ma_ldrh(EDtrAddr(r1, EDtrOffImm(JSFunction::offsetOfNargs())), r6);
masm.ma_sub(r6, r8, r2); masm.ma_sub(r6, r8, r2);

Просмотреть файл

@ -363,7 +363,7 @@ JitRuntime::generateArgumentsRectifier(JSContext *cx, ExecutionMode mode, void *
// Load the number of |undefined|s to push into %rcx. // Load the number of |undefined|s to push into %rcx.
masm.loadPtr(Address(rsp, IonRectifierFrameLayout::offsetOfCalleeToken()), rax); masm.loadPtr(Address(rsp, IonRectifierFrameLayout::offsetOfCalleeToken()), rax);
masm.movzwl(Operand(rax, offsetof(JSFunction, nargs)), rcx); masm.movzwl(Operand(rax, JSFunction::offsetOfNargs()), rcx);
masm.subq(r8, rcx); masm.subq(r8, rcx);
// Copy the number of actual arguments // Copy the number of actual arguments

Просмотреть файл

@ -353,7 +353,7 @@ JitRuntime::generateArgumentsRectifier(JSContext *cx, ExecutionMode mode, void *
// Load the number of |undefined|s to push into %ecx. // Load the number of |undefined|s to push into %ecx.
masm.loadPtr(Address(esp, IonRectifierFrameLayout::offsetOfCalleeToken()), eax); masm.loadPtr(Address(esp, IonRectifierFrameLayout::offsetOfCalleeToken()), eax);
masm.movzwl(Operand(eax, offsetof(JSFunction, nargs)), ecx); masm.movzwl(Operand(eax, JSFunction::offsetOfNargs()), ecx);
masm.subl(esi, ecx); masm.subl(esi, ecx);
// Copy the number of actual arguments. // Copy the number of actual arguments.

Просмотреть файл

@ -225,7 +225,7 @@ static inline uint32_t ArgSlot(uint32_t arg) {
return 1 + arg; return 1 + arg;
} }
static inline uint32_t LocalSlot(JSScript *script, uint32_t local) { static inline uint32_t LocalSlot(JSScript *script, uint32_t local) {
return 1 + (script->function() ? script->function()->nargs : 0) + local; return 1 + (script->function() ? script->function()->nargs() : 0) + local;
} }
static inline uint32_t TotalSlots(JSScript *script) { static inline uint32_t TotalSlots(JSScript *script) {
return LocalSlot(script, 0) + script->nfixed(); return LocalSlot(script, 0) + script->nfixed();

Просмотреть файл

@ -4014,7 +4014,7 @@ JS_GetFunctionDisplayId(JSFunction *fun)
JS_PUBLIC_API(uint16_t) JS_PUBLIC_API(uint16_t)
JS_GetFunctionArity(JSFunction *fun) JS_GetFunctionArity(JSFunction *fun)
{ {
return fun->nargs; return fun->nargs();
} }
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)

Просмотреть файл

@ -302,7 +302,7 @@ js::fun_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
if (fun->isInterpretedLazy() && !fun->getOrCreateScript(cx)) if (fun->isInterpretedLazy() && !fun->getOrCreateScript(cx))
return false; return false;
uint16_t length = fun->hasScript() ? fun->nonLazyScript()->funLength() : uint16_t length = fun->hasScript() ? fun->nonLazyScript()->funLength() :
fun->nargs - fun->hasRest(); fun->nargs() - fun->hasRest();
v.setInt32(length); v.setInt32(length);
} else { } else {
v.setString(fun->atom() == nullptr ? cx->runtime()->emptyString : fun->atom()); v.setString(fun->atom() == nullptr ? cx->runtime()->emptyString : fun->atom());
@ -387,7 +387,7 @@ js::XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope, Han
if (!script) if (!script)
return false; return false;
atom = fun->atom(); atom = fun->atom();
flagsword = (fun->nargs << 16) | fun->flags; flagsword = (fun->nargs() << 16) | fun->flags();
if (!xdr->codeUint32(&firstword)) if (!xdr->codeUint32(&firstword))
return false; return false;
@ -419,14 +419,14 @@ js::XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope, Han
return false; return false;
if (mode == XDR_DECODE) { if (mode == XDR_DECODE) {
fun->nargs = flagsword >> 16; fun->setArgCount(flagsword >> 16);
fun->flags = uint16_t(flagsword); fun->setFlags(uint16_t(flagsword));
fun->initAtom(atom); fun->initAtom(atom);
fun->initScript(script); fun->initScript(script);
script->setFunction(fun); script->setFunction(fun);
if (!JSFunction::setTypeForScriptedFunction(cx, fun)) if (!JSFunction::setTypeForScriptedFunction(cx, fun))
return false; return false;
JS_ASSERT(fun->nargs == fun->nonLazyScript()->bindings.numArgs()); JS_ASSERT(fun->nargs() == fun->nonLazyScript()->bindings.numArgs());
RootedScript script(cx, fun->nonLazyScript()); RootedScript script(cx, fun->nonLazyScript());
CallNewScriptHook(cx, script, fun); CallNewScriptHook(cx, script, fun);
objp.set(fun); objp.set(fun);
@ -463,8 +463,8 @@ js::CloneFunctionAndScript(JSContext *cx, HandleObject enclosingScope, HandleFun
if (!clonedScript) if (!clonedScript)
return nullptr; return nullptr;
clone->nargs = srcFun->nargs; clone->setArgCount(srcFun->nargs());
clone->flags = srcFun->flags; clone->setFlags(srcFun->flags());
clone->initAtom(srcFun->displayAtom()); clone->initAtom(srcFun->displayAtom());
clone->initScript(clonedScript); clone->initScript(clonedScript);
clonedScript->setFunction(clone); clonedScript->setFunction(clone);
@ -717,9 +717,9 @@ js::FunctionToString(JSContext *cx, HandleFunction fun, bool bodyOnly, bool lamb
ScopedJSDeletePtr<BindingVector> freeNames(localNames); ScopedJSDeletePtr<BindingVector> freeNames(localNames);
if (!FillBindingVector(script, localNames)) if (!FillBindingVector(script, localNames))
return nullptr; return nullptr;
for (unsigned i = 0; i < fun->nargs; i++) { for (unsigned i = 0; i < fun->nargs(); i++) {
if ((i && !out.append(", ")) || if ((i && !out.append(", ")) ||
(i == unsigned(fun->nargs - 1) && fun->hasRest() && !out.append("...")) || (i == unsigned(fun->nargs() - 1) && fun->hasRest() && !out.append("...")) ||
!out.append((*localNames)[i].name())) { !out.append((*localNames)[i].name())) {
return nullptr; return nullptr;
} }
@ -1124,8 +1124,8 @@ JSFunction::createScriptForLazilyInterpretedFunction(JSContext *cx, HandleFuncti
// THING_ROOT_LAZY_SCRIPT). // THING_ROOT_LAZY_SCRIPT).
AutoSuppressGC suppressGC(cx); AutoSuppressGC suppressGC(cx);
fun->flags &= ~INTERPRETED_LAZY; fun->flags_ &= ~INTERPRETED_LAZY;
fun->flags |= INTERPRETED; fun->flags_ |= INTERPRETED;
RootedScript script(cx, lazy->maybeScript()); RootedScript script(cx, lazy->maybeScript());
@ -1333,7 +1333,7 @@ js_fun_bind(JSContext *cx, HandleObject target, HandleValue thisArg,
/* Steps 15-16. */ /* Steps 15-16. */
unsigned length = 0; unsigned length = 0;
if (target->is<JSFunction>()) { if (target->is<JSFunction>()) {
unsigned nargs = target->as<JSFunction>().nargs; unsigned nargs = target->as<JSFunction>().nargs();
if (nargs > argslen) if (nargs > argslen)
length = nargs - argslen; length = nargs - argslen;
} }
@ -1662,9 +1662,12 @@ js::NewFunctionWithProto(ExclusiveContext *cx, HandleObject funobjArg, Native na
} }
RootedFunction fun(cx, &funobj->as<JSFunction>()); RootedFunction fun(cx, &funobj->as<JSFunction>());
if (allocKind == JSFunction::ExtendedFinalizeKind)
flags = JSFunction::Flags(flags | JSFunction::EXTENDED);
/* Initialize all function members. */ /* Initialize all function members. */
fun->nargs = uint16_t(nargs); fun->setArgCount(uint16_t(nargs));
fun->flags = flags; fun->setFlags(flags);
if (fun->isInterpreted()) { if (fun->isInterpreted()) {
JS_ASSERT(!native); JS_ASSERT(!native);
fun->mutableScript().init(nullptr); fun->mutableScript().init(nullptr);
@ -1674,10 +1677,8 @@ js::NewFunctionWithProto(ExclusiveContext *cx, HandleObject funobjArg, Native na
JS_ASSERT(native); JS_ASSERT(native);
fun->initNative(native, nullptr); fun->initNative(native, nullptr);
} }
if (allocKind == JSFunction::ExtendedFinalizeKind) { if (allocKind == JSFunction::ExtendedFinalizeKind)
fun->flags |= JSFunction::EXTENDED;
fun->initializeExtended(); fun->initializeExtended();
}
fun->initAtom(atom); fun->initAtom(atom);
return fun; return fun;
@ -1710,8 +1711,12 @@ js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
return nullptr; return nullptr;
RootedFunction clone(cx, &cloneobj->as<JSFunction>()); RootedFunction clone(cx, &cloneobj->as<JSFunction>());
clone->nargs = fun->nargs; uint16_t flags = fun->flags() & ~JSFunction::EXTENDED;
clone->flags = fun->flags & ~JSFunction::EXTENDED; if (allocKind == JSFunction::ExtendedFinalizeKind)
flags |= JSFunction::EXTENDED;
clone->setArgCount(fun->nargs());
clone->setFlags(flags);
if (fun->hasScript()) { if (fun->hasScript()) {
clone->initScript(fun->nonLazyScript()); clone->initScript(fun->nonLazyScript());
clone->initEnvironment(parent); clone->initEnvironment(parent);
@ -1725,7 +1730,6 @@ js::CloneFunctionObject(JSContext *cx, HandleFunction fun, HandleObject parent,
clone->initAtom(fun->displayAtom()); clone->initAtom(fun->displayAtom());
if (allocKind == JSFunction::ExtendedFinalizeKind) { if (allocKind == JSFunction::ExtendedFinalizeKind) {
clone->flags |= JSFunction::EXTENDED;
if (fun->isExtended() && fun->compartment() == cx->compartment()) { if (fun->isExtended() && fun->compartment() == cx->compartment()) {
for (unsigned i = 0; i < FunctionExtended::NUM_EXTENDED_SLOTS; i++) for (unsigned i = 0; i < FunctionExtended::NUM_EXTENDED_SLOTS; i++)
clone->initExtendedSlot(i, fun->getExtendedSlot(i)); clone->initExtendedSlot(i, fun->getExtendedSlot(i));

Просмотреть файл

@ -63,9 +63,10 @@ class JSFunction : public JSObject
"shadow interface must match actual interface"); "shadow interface must match actual interface");
} }
uint16_t nargs; /* number of formal arguments private:
uint16_t nargs_; /* number of formal arguments
(including defaults and the rest parameter unlike f.length) */ (including defaults and the rest parameter unlike f.length) */
uint16_t flags; /* bitfield composed of the above Flags enum */ uint16_t flags_; /* bitfield composed of the above Flags enum */
union U { union U {
class Native { class Native {
friend class JSFunction; friend class JSFunction;
@ -85,7 +86,6 @@ class JSFunction : public JSObject
} i; } i;
void *nativeOrScript; void *nativeOrScript;
} u; } u;
private:
js::HeapPtrAtom atom_; /* name for diagnostics and decompiling */ js::HeapPtrAtom atom_; /* name for diagnostics and decompiling */
public: public:
@ -104,26 +104,36 @@ class JSFunction : public JSObject
isGenerator(); isGenerator();
} }
size_t nargs() const {
js::AutoThreadSafeAccess ts(this);
return nargs_;
}
uint16_t flags() const {
js::AutoThreadSafeAccess ts(this);
return flags_;
}
/* A function can be classified as either native (C++) or interpreted (JS): */ /* A function can be classified as either native (C++) or interpreted (JS): */
bool isInterpreted() const { return flags & (INTERPRETED | INTERPRETED_LAZY); } bool isInterpreted() const { return flags() & (INTERPRETED | INTERPRETED_LAZY); }
bool isNative() const { return !isInterpreted(); } bool isNative() const { return !isInterpreted(); }
/* Possible attributes of a native function: */ /* Possible attributes of a native function: */
bool isNativeConstructor() const { return flags & NATIVE_CTOR; } bool isNativeConstructor() const { return flags() & NATIVE_CTOR; }
/* Possible attributes of an interpreted function: */ /* Possible attributes of an interpreted function: */
bool isFunctionPrototype() const { return flags & IS_FUN_PROTO; } bool isFunctionPrototype() const { return flags() & IS_FUN_PROTO; }
bool isInterpretedLazy() const { return flags & INTERPRETED_LAZY; } bool isInterpretedLazy() const { return flags() & INTERPRETED_LAZY; }
bool hasScript() const { return flags & INTERPRETED; } bool hasScript() const { return flags() & INTERPRETED; }
bool isExprClosure() const { return flags & EXPR_CLOSURE; } bool isExprClosure() const { return flags() & EXPR_CLOSURE; }
bool hasGuessedAtom() const { return flags & HAS_GUESSED_ATOM; } bool hasGuessedAtom() const { return flags() & HAS_GUESSED_ATOM; }
bool isLambda() const { return flags & LAMBDA; } bool isLambda() const { return flags() & LAMBDA; }
bool isSelfHostedBuiltin() const { return flags & SELF_HOSTED; } bool isSelfHostedBuiltin() const { return flags() & SELF_HOSTED; }
bool isSelfHostedConstructor() const { return flags & SELF_HOSTED_CTOR; } bool isSelfHostedConstructor() const { return flags() & SELF_HOSTED_CTOR; }
bool hasRest() const { return flags & HAS_REST; } bool hasRest() const { return flags() & HAS_REST; }
bool isWrappable() const { bool isWrappable() const {
JS_ASSERT_IF(flags & SH_WRAPPABLE, isSelfHostedBuiltin()); JS_ASSERT_IF(flags() & SH_WRAPPABLE, isSelfHostedBuiltin());
return flags & SH_WRAPPABLE; return flags() & SH_WRAPPABLE;
} }
bool hasJITCode() const { bool hasJITCode() const {
@ -144,7 +154,7 @@ class JSFunction : public JSObject
// //
// isArrow() is true for all three of these Function objects. // isArrow() is true for all three of these Function objects.
// isBoundFunction() is true only for the last one. // isBoundFunction() is true only for the last one.
bool isArrow() const { return flags & ARROW; } bool isArrow() const { return flags() & ARROW; }
/* Compound attributes: */ /* Compound attributes: */
bool isBuiltin() const { bool isBuiltin() const {
@ -170,40 +180,48 @@ class JSFunction : public JSObject
return nonLazyScript()->strict(); return nonLazyScript()->strict();
} }
void setFlags(uint16_t flags) {
this->flags_ = flags;
}
// Can be called multiple times by the parser. // Can be called multiple times by the parser.
void setArgCount(uint16_t nargs) { void setArgCount(uint16_t nargs) {
this->nargs = nargs; this->nargs_ = nargs;
} }
// Can be called multiple times by the parser. // Can be called multiple times by the parser.
void setHasRest() { void setHasRest() {
flags |= HAS_REST; flags_ |= HAS_REST;
} }
void setIsSelfHostedBuiltin() { void setIsSelfHostedBuiltin() {
JS_ASSERT(!isSelfHostedBuiltin()); JS_ASSERT(!isSelfHostedBuiltin());
flags |= SELF_HOSTED; flags_ |= SELF_HOSTED;
} }
void setIsSelfHostedConstructor() { void setIsSelfHostedConstructor() {
JS_ASSERT(!isSelfHostedConstructor()); JS_ASSERT(!isSelfHostedConstructor());
flags |= SELF_HOSTED_CTOR; flags_ |= SELF_HOSTED_CTOR;
} }
void makeWrappable() { void makeWrappable() {
JS_ASSERT(isSelfHostedBuiltin()); JS_ASSERT(isSelfHostedBuiltin());
JS_ASSERT(!isWrappable()); JS_ASSERT(!isWrappable());
flags |= SH_WRAPPABLE; flags_ |= SH_WRAPPABLE;
} }
void setIsFunctionPrototype() { void setIsFunctionPrototype() {
JS_ASSERT(!isFunctionPrototype()); JS_ASSERT(!isFunctionPrototype());
flags |= IS_FUN_PROTO; flags_ |= IS_FUN_PROTO;
} }
// Can be called multiple times by the parser. // Can be called multiple times by the parser.
void setIsExprClosure() { void setIsExprClosure() {
flags |= EXPR_CLOSURE; flags_ |= EXPR_CLOSURE;
}
void setArrow() {
flags_ |= ARROW;
} }
JSAtom *atom() const { return hasGuessedAtom() ? nullptr : atom_.get(); } JSAtom *atom() const { return hasGuessedAtom() ? nullptr : atom_.get(); }
@ -216,7 +234,7 @@ class JSFunction : public JSObject
JS_ASSERT(atom != nullptr); JS_ASSERT(atom != nullptr);
JS_ASSERT(!hasGuessedAtom()); JS_ASSERT(!hasGuessedAtom());
atom_ = atom; atom_ = atom;
flags |= HAS_GUESSED_ATOM; flags_ |= HAS_GUESSED_ATOM;
} }
/* uint16_t representation bounds number of call object dynamic slots. */ /* uint16_t representation bounds number of call object dynamic slots. */
@ -241,6 +259,8 @@ class JSFunction : public JSObject
((js::HeapPtrObject *)&u.i.env_)->init(obj); ((js::HeapPtrObject *)&u.i.env_)->init(obj);
} }
static inline size_t offsetOfNargs() { return offsetof(JSFunction, nargs_); }
static inline size_t offsetOfFlags() { return offsetof(JSFunction, flags_); }
static inline size_t offsetOfEnvironment() { return offsetof(JSFunction, u.i.env_); } static inline size_t offsetOfEnvironment() { return offsetof(JSFunction, u.i.env_); }
static inline size_t offsetOfAtom() { return offsetof(JSFunction, atom_); } static inline size_t offsetOfAtom() { return offsetof(JSFunction, atom_); }
@ -291,8 +311,8 @@ class JSFunction : public JSObject
if (shadowZone()->needsBarrier()) if (shadowZone()->needsBarrier())
js::LazyScript::writeBarrierPre(lazy); js::LazyScript::writeBarrierPre(lazy);
flags &= ~INTERPRETED_LAZY; flags_ &= ~INTERPRETED_LAZY;
flags |= INTERPRETED; flags_ |= INTERPRETED;
initScript(script); initScript(script);
} }
JS_ASSERT(hasScript()); JS_ASSERT(hasScript());
@ -348,8 +368,8 @@ class JSFunction : public JSObject
void initLazyScript(js::LazyScript *lazy) { void initLazyScript(js::LazyScript *lazy) {
JS_ASSERT(isInterpreted()); JS_ASSERT(isInterpreted());
flags &= ~INTERPRETED; flags_ &= ~INTERPRETED;
flags |= INTERPRETED_LAZY; flags_ |= INTERPRETED_LAZY;
u.i.s.lazy_ = lazy; u.i.s.lazy_ = lazy;
} }
@ -426,8 +446,8 @@ class JSFunction : public JSObject
public: public:
inline bool isExtended() const { inline bool isExtended() const {
JS_STATIC_ASSERT(FinalizeKind != ExtendedFinalizeKind); JS_STATIC_ASSERT(FinalizeKind != ExtendedFinalizeKind);
JS_ASSERT_IF(isTenured(), !!(flags & EXTENDED) == (tenuredGetAllocKind() == ExtendedFinalizeKind)); JS_ASSERT_IF(isTenured(), !!(flags() & EXTENDED) == (tenuredGetAllocKind() == ExtendedFinalizeKind));
return !!(flags & EXTENDED); return !!(flags() & EXTENDED);
} }
/* /*

Просмотреть файл

@ -692,7 +692,7 @@ TypeScript::FreezeTypeSets(CompilerConstraintList *constraints, JSScript *script
} }
*pThisTypes = types + (ThisTypes(script) - existing); *pThisTypes = types + (ThisTypes(script) - existing);
*pArgTypes = (script->function() && script->function()->nargs) *pArgTypes = (script->function() && script->function()->nargs())
? (types + (ArgTypes(script, 0) - existing)) ? (types + (ArgTypes(script, 0) - existing))
: nullptr; : nullptr;
*pBytecodeTypes = types; *pBytecodeTypes = types;
@ -972,7 +972,7 @@ types::FinishCompilation(JSContext *cx, HandleScript script, ExecutionMode execu
if (!CheckFrozenTypeSet(cx, entry.thisTypes, types::TypeScript::ThisTypes(entry.script))) if (!CheckFrozenTypeSet(cx, entry.thisTypes, types::TypeScript::ThisTypes(entry.script)))
succeeded = false; succeeded = false;
unsigned nargs = entry.script->function() ? entry.script->function()->nargs : 0; unsigned nargs = entry.script->function() ? entry.script->function()->nargs() : 0;
for (size_t i = 0; i < nargs; i++) { for (size_t i = 0; i < nargs; i++) {
if (!CheckFrozenTypeSet(cx, &entry.argTypes[i], types::TypeScript::ArgTypes(entry.script, i))) if (!CheckFrozenTypeSet(cx, &entry.argTypes[i], types::TypeScript::ArgTypes(entry.script, i)))
succeeded = false; succeeded = false;
@ -3354,7 +3354,7 @@ void
types::TypeMonitorCallSlow(JSContext *cx, JSObject *callee, const CallArgs &args, types::TypeMonitorCallSlow(JSContext *cx, JSObject *callee, const CallArgs &args,
bool constructing) bool constructing)
{ {
unsigned nargs = callee->as<JSFunction>().nargs; unsigned nargs = callee->as<JSFunction>().nargs();
JSScript *script = callee->as<JSFunction>().nonLazyScript(); JSScript *script = callee->as<JSFunction>().nonLazyScript();
if (!constructing) if (!constructing)
@ -3505,7 +3505,7 @@ JSScript::makeTypes(JSContext *cx)
InferSpew(ISpewOps, "typeSet: %sT%p%s this #%u", InferSpew(ISpewOps, "typeSet: %sT%p%s this #%u",
InferSpewColor(thisTypes), thisTypes, InferSpewColorReset(), InferSpewColor(thisTypes), thisTypes, InferSpewColorReset(),
id()); id());
unsigned nargs = function() ? function()->nargs : 0; unsigned nargs = function() ? function()->nargs() : 0;
for (unsigned i = 0; i < nargs; i++) { for (unsigned i = 0; i < nargs; i++) {
TypeSet *types = TypeScript::ArgTypes(this, i); TypeSet *types = TypeScript::ArgTypes(this, i);
InferSpew(ISpewOps, "typeSet: %sT%p%s arg%u #%u", InferSpew(ISpewOps, "typeSet: %sT%p%s arg%u #%u",
@ -4385,7 +4385,7 @@ TypeScript::printTypes(JSContext *cx, HandleScript script) const
fprintf(stderr, "\n this:"); fprintf(stderr, "\n this:");
TypeScript::ThisTypes(script)->print(); TypeScript::ThisTypes(script)->print();
for (unsigned i = 0; script->function() && i < script->function()->nargs; i++) { for (unsigned i = 0; script->function() && i < script->function()->nargs(); i++) {
fprintf(stderr, "\n arg%u:", i); fprintf(stderr, "\n arg%u:", i);
TypeScript::ArgTypes(script, i)->print(); TypeScript::ArgTypes(script, i)->print();
} }

Просмотреть файл

@ -617,7 +617,7 @@ TypeScript::ThisTypes(JSScript *script)
/* static */ inline StackTypeSet * /* static */ inline StackTypeSet *
TypeScript::ArgTypes(JSScript *script, unsigned i) TypeScript::ArgTypes(JSScript *script, unsigned i)
{ {
JS_ASSERT(i < script->function()->nargs); JS_ASSERT(i < script->function()->nargs());
return script->types->typeArray() + script->nTypeSets() + js::analyze::ArgSlot(i); return script->types->typeArray() + script->nTypeSets() + js::analyze::ArgSlot(i);
} }

Просмотреть файл

@ -410,7 +410,7 @@ class BytecodeParser
} }
uint32_t numSlots() { uint32_t numSlots() {
return 1 + (script_->function() ? script_->function()->nargs : 0) + script_->nfixed(); return 1 + (script_->function() ? script_->function()->nargs() : 0) + script_->nfixed();
} }
uint32_t maximumStackDepth() { uint32_t maximumStackDepth() {
@ -1688,7 +1688,7 @@ JSAtom *
ExpressionDecompiler::getVar(unsigned slot) ExpressionDecompiler::getVar(unsigned slot)
{ {
JS_ASSERT(fun); JS_ASSERT(fun);
slot += fun->nargs; slot += fun->nargs();
JS_ASSERT(slot < script->bindings.count()); JS_ASSERT(slot < script->bindings.count());
return (*localNames)[slot].name(); return (*localNames)[slot].name();
} }

Просмотреть файл

@ -96,7 +96,7 @@ struct CopyIonJSFrameArgs
void copyArgs(JSContext *, HeapValue *dstBase, unsigned totalArgs) const { void copyArgs(JSContext *, HeapValue *dstBase, unsigned totalArgs) const {
unsigned numActuals = frame_->numActualArgs(); unsigned numActuals = frame_->numActualArgs();
unsigned numFormals = jit::CalleeTokenToFunction(frame_->calleeToken())->nargs; unsigned numFormals = jit::CalleeTokenToFunction(frame_->calleeToken())->nargs();
JS_ASSERT(numActuals <= totalArgs); JS_ASSERT(numActuals <= totalArgs);
JS_ASSERT(numFormals <= totalArgs); JS_ASSERT(numFormals <= totalArgs);
JS_ASSERT(Max(numActuals, numFormals) == totalArgs); JS_ASSERT(Max(numActuals, numFormals) == totalArgs);
@ -144,7 +144,7 @@ struct CopyScriptFrameIterArgs
/* Define formals which are not part of the actuals. */ /* Define formals which are not part of the actuals. */
unsigned numActuals = iter_.numActualArgs(); unsigned numActuals = iter_.numActualArgs();
unsigned numFormals = iter_.callee()->nargs; unsigned numFormals = iter_.callee()->nargs();
JS_ASSERT(numActuals <= totalArgs); JS_ASSERT(numActuals <= totalArgs);
JS_ASSERT(numFormals <= totalArgs); JS_ASSERT(numFormals <= totalArgs);
JS_ASSERT(Max(numActuals, numFormals) == totalArgs); JS_ASSERT(Max(numActuals, numFormals) == totalArgs);
@ -192,7 +192,7 @@ ArgumentsObject::create(JSContext *cx, HandleScript script, HandleFunction calle
if (!shape) if (!shape)
return nullptr; return nullptr;
unsigned numFormals = callee->nargs; unsigned numFormals = callee->nargs();
unsigned numDeletedWords = NumWordsForBitArrayOfLength(numActuals); unsigned numDeletedWords = NumWordsForBitArrayOfLength(numActuals);
unsigned numArgs = Max(numActuals, numFormals); unsigned numArgs = Max(numActuals, numFormals);
unsigned numBytes = offsetof(ArgumentsData, args) + unsigned numBytes = offsetof(ArgumentsData, args) +
@ -341,7 +341,7 @@ ArgSetter(JSContext *cx, HandleObject obj, HandleId id, bool strict, MutableHand
unsigned arg = unsigned(JSID_TO_INT(id)); unsigned arg = unsigned(JSID_TO_INT(id));
if (arg < argsobj.initialLength() && !argsobj.isElementDeleted(arg)) { if (arg < argsobj.initialLength() && !argsobj.isElementDeleted(arg)) {
argsobj.setElement(cx, arg, vp); argsobj.setElement(cx, arg, vp);
if (arg < script->function()->nargs) if (arg < script->function()->nargs())
types::TypeScript::SetArgument(cx, script, arg, vp); types::TypeScript::SetArgument(cx, script, arg, vp);
return true; return true;
} }

Просмотреть файл

@ -4720,23 +4720,23 @@ DebuggerObject_getParameterNames(JSContext *cx, unsigned argc, Value *vp)
return true; return true;
} }
RootedObject result(cx, NewDenseAllocatedArray(cx, fun->nargs)); RootedObject result(cx, NewDenseAllocatedArray(cx, fun->nargs()));
if (!result) if (!result)
return false; return false;
result->ensureDenseInitializedLength(cx, 0, fun->nargs); result->ensureDenseInitializedLength(cx, 0, fun->nargs());
if (fun->isInterpreted()) { if (fun->isInterpreted()) {
RootedScript script(cx, GetOrCreateFunctionScript(cx, fun)); RootedScript script(cx, GetOrCreateFunctionScript(cx, fun));
if (!script) if (!script)
return false; return false;
JS_ASSERT(fun->nargs == script->bindings.numArgs()); JS_ASSERT(fun->nargs() == script->bindings.numArgs());
if (fun->nargs > 0) { if (fun->nargs() > 0) {
BindingVector bindings(cx); BindingVector bindings(cx);
if (!FillBindingVector(script, &bindings)) if (!FillBindingVector(script, &bindings))
return false; return false;
for (size_t i = 0; i < fun->nargs; i++) { for (size_t i = 0; i < fun->nargs(); i++) {
Value v; Value v;
if (bindings[i].name()->length() == 0) if (bindings[i].name()->length() == 0)
v = UndefinedValue(); v = UndefinedValue();
@ -4746,7 +4746,7 @@ DebuggerObject_getParameterNames(JSContext *cx, unsigned argc, Value *vp)
} }
} }
} else { } else {
for (size_t i = 0; i < fun->nargs; i++) for (size_t i = 0; i < fun->nargs(); i++)
result->setDenseElement(i, UndefinedValue()); result->setDenseElement(i, UndefinedValue());
} }

Просмотреть файл

@ -3609,7 +3609,7 @@ js::Lambda(JSContext *cx, HandleFunction fun, HandleObject parent)
clone = js_fun_bind(cx, clone, thisval, nullptr, 0); clone = js_fun_bind(cx, clone, thisval, nullptr, 0);
if (!clone) if (!clone)
return nullptr; return nullptr;
clone->as<JSFunction>().flags |= JSFunction::ARROW; clone->as<JSFunction>().setArrow();
} }
JS_ASSERT(clone->global() == clone->global()); JS_ASSERT(clone->global() == clone->global());

Просмотреть файл

@ -450,7 +450,7 @@ JS_GetLinePCs(JSContext *cx, JSScript *script,
JS_PUBLIC_API(unsigned) JS_PUBLIC_API(unsigned)
JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun) JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun)
{ {
return fun->nargs; return fun->nargs();
} }
JS_PUBLIC_API(bool) JS_PUBLIC_API(bool)

Просмотреть файл

@ -960,8 +960,8 @@ JSRuntime::cloneSelfHostedFunctionScript(JSContext *cx, Handle<PropertyName*> na
return false; return false;
targetFun->setScript(cscript); targetFun->setScript(cscript);
cscript->setFunction(targetFun); cscript->setFunction(targetFun);
JS_ASSERT(sourceFun->nargs == targetFun->nargs); JS_ASSERT(sourceFun->nargs() == targetFun->nargs());
targetFun->flags = sourceFun->flags | JSFunction::EXTENDED; targetFun->setFlags(sourceFun->flags() | JSFunction::EXTENDED);
return true; return true;
} }

Просмотреть файл

@ -253,7 +253,7 @@ InterpreterStack::getCallFrame(JSContext *cx, const CallArgs &args, HandleScript
JSFunction *fun = &args.callee().as<JSFunction>(); JSFunction *fun = &args.callee().as<JSFunction>();
JS_ASSERT(fun->nonLazyScript() == script); JS_ASSERT(fun->nonLazyScript() == script);
unsigned nformal = fun->nargs; unsigned nformal = fun->nargs();
unsigned nvals = script->nslots(); unsigned nvals = script->nslots();
if (args.length() >= nformal) { if (args.length() >= nformal) {

Просмотреть файл

@ -165,7 +165,7 @@ JSObject *
StackFrame::createRestParameter(JSContext *cx) StackFrame::createRestParameter(JSContext *cx)
{ {
JS_ASSERT(fun()->hasRest()); JS_ASSERT(fun()->hasRest());
unsigned nformal = fun()->nargs - 1, nactual = numActualArgs(); unsigned nformal = fun()->nargs() - 1, nactual = numActualArgs();
unsigned nrest = (nactual > nformal) ? nactual - nformal : 0; unsigned nrest = (nactual > nformal) ? nactual - nformal : 0;
Value *restvp = argv() + nformal; Value *restvp = argv() + nformal;
JSObject *obj = NewDenseCopiedArray(cx, nrest, restvp, nullptr); JSObject *obj = NewDenseCopiedArray(cx, nrest, restvp, nullptr);

Просмотреть файл

@ -534,7 +534,7 @@ class StackFrame
bool copyRawFrameSlots(AutoValueVector *v); bool copyRawFrameSlots(AutoValueVector *v);
unsigned numFormalArgs() const { JS_ASSERT(hasArgs()); return fun()->nargs; } unsigned numFormalArgs() const { JS_ASSERT(hasArgs()); return fun()->nargs(); }
unsigned numActualArgs() const { JS_ASSERT(hasArgs()); return u.nactual; } unsigned numActualArgs() const { JS_ASSERT(hasArgs()); return u.nactual; }
inline Value &canonicalActualArg(unsigned i) const; inline Value &canonicalActualArg(unsigned i) const;
@ -1563,7 +1563,7 @@ class ScriptFrameIter
JSFunction *callee() const; JSFunction *callee() const;
Value calleev() const; Value calleev() const;
unsigned numActualArgs() const; unsigned numActualArgs() const;
unsigned numFormalArgs() const { return script()->function()->nargs; } unsigned numFormalArgs() const { return script()->function()->nargs(); }
Value unaliasedActual(unsigned i, MaybeCheckAliasing = CHECK_ALIASING) const; Value unaliasedActual(unsigned i, MaybeCheckAliasing = CHECK_ALIASING) const;
JSObject *scopeChain() const; JSObject *scopeChain() const;