Commit 279085d8 authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

[builtins] Refactor the NumberConstructor builtin

This patch removes the NumberConstructor_ConstructStub builtin,
merging its functionality into the refactored NumberConstructor
TurboFan builtin.

This brings us closer to our goal of deprecating the `construct_stub`
field in `SharedFunctionInfo`.

Bug: v8:7503, v8:7518
Change-Id: Ia407a2d43cda9fc7b26e13274fd79f110b6232ca
Reviewed-on: https://chromium-review.googlesource.com/946008
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51694}
parent c00764b6
...@@ -1791,7 +1791,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1791,7 +1791,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
number_fun->shared()->set_builtin_function_id(kNumberConstructor); number_fun->shared()->set_builtin_function_id(kNumberConstructor);
number_fun->shared()->DontAdaptArguments(); number_fun->shared()->DontAdaptArguments();
number_fun->shared()->SetConstructStub( number_fun->shared()->SetConstructStub(
*BUILTIN_CODE(isolate, NumberConstructor_ConstructStub)); *BUILTIN_CODE(isolate, JSBuiltinsConstructStub));
number_fun->shared()->set_length(1); number_fun->shared()->set_length(1);
InstallWithIntrinsicDefaultProto(isolate, number_fun, InstallWithIntrinsicDefaultProto(isolate, number_fun,
Context::NUMBER_FUNCTION_INDEX); Context::NUMBER_FUNCTION_INDEX);
......
...@@ -690,46 +690,51 @@ TF_BUILTIN(ObjectConstructor, ConstructorBuiltinsAssembler) { ...@@ -690,46 +690,51 @@ TF_BUILTIN(ObjectConstructor, ConstructorBuiltinsAssembler) {
args.PopAndReturn(var_result.value()); args.PopAndReturn(var_result.value());
} }
// ES #sec-number-constructor
TF_BUILTIN(NumberConstructor, ConstructorBuiltinsAssembler) { TF_BUILTIN(NumberConstructor, ConstructorBuiltinsAssembler) {
Node* argc =
ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount));
CodeStubArguments args(this, argc);
Label return_zero(this);
GotoIf(IntPtrEqual(IntPtrConstant(0), argc), &return_zero);
Node* context = Parameter(BuiltinDescriptor::kContext);
args.PopAndReturn(
ToNumber(context, args.AtIndex(0), BigIntHandling::kConvertToNumber));
BIND(&return_zero);
args.PopAndReturn(SmiConstant(0));
}
TF_BUILTIN(NumberConstructor_ConstructStub, ConstructorBuiltinsAssembler) {
Node* target = LoadFromFrame(StandardFrameConstants::kFunctionOffset,
MachineType::TaggedPointer());
Node* new_target = Parameter(BuiltinDescriptor::kNewTarget);
Node* context = Parameter(BuiltinDescriptor::kContext); Node* context = Parameter(BuiltinDescriptor::kContext);
Node* argc = Node* argc =
ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount));
CodeStubArguments args(this, argc); CodeStubArguments args(this, argc);
Label wrap(this); // 1. If no arguments were passed to this function invocation, let n be +0.
VARIABLE(var_n, MachineRepresentation::kTagged, SmiConstant(0));
Label if_nloaded(this, &var_n);
GotoIf(WordEqual(argc, IntPtrConstant(0)), &if_nloaded);
// 2. Else,
// a. Let prim be ? ToNumeric(value).
// b. If Type(prim) is BigInt, let n be the Number value for prim.
// c. Otherwise, let n be prim.
Node* value = args.AtIndex(0);
var_n.Bind(ToNumber(context, value, BigIntHandling::kConvertToNumber));
Goto(&if_nloaded);
VARIABLE(var_result, MachineRepresentation::kTagged, SmiConstant(0)); BIND(&if_nloaded);
{
// 3. If NewTarget is undefined, return n.
Node* n_value = var_n.value();
Node* new_target = Parameter(BuiltinDescriptor::kNewTarget);
Label return_n(this), constructnumber(this, Label::kDeferred);
Branch(IsUndefined(new_target), &return_n, &constructnumber);
GotoIf(IntPtrEqual(IntPtrConstant(0), argc), &wrap); BIND(&return_n);
var_result.Bind( { args.PopAndReturn(n_value); }
ToNumber(context, args.AtIndex(0), BigIntHandling::kConvertToNumber));
Goto(&wrap);
BIND(&wrap); BIND(&constructnumber);
Node* result = EmitFastNewObject(context, target, new_target); {
StoreObjectField(result, JSValue::kValueOffset, var_result.value()); // 4. Let O be ? OrdinaryCreateFromConstructor(NewTarget,
args.PopAndReturn(result); // "%NumberPrototype%", « [[NumberData]] »).
// 5. Set O.[[NumberData]] to n.
// 6. Return O.
Node* target = LoadFromFrame(StandardFrameConstants::kFunctionOffset,
MachineType::TaggedPointer());
Node* result =
CallBuiltin(Builtins::kFastNewObject, context, target, new_target);
StoreObjectField(result, JSValue::kValueOffset, n_value);
args.PopAndReturn(result);
}
}
} }
// https://tc39.github.io/ecma262/#sec-string-constructor // https://tc39.github.io/ecma262/#sec-string-constructor
......
...@@ -698,11 +698,8 @@ namespace internal { ...@@ -698,11 +698,8 @@ namespace internal {
\ \
/* Number */ \ /* Number */ \
TFC(AllocateHeapNumber, AllocateHeapNumber, 1) \ TFC(AllocateHeapNumber, AllocateHeapNumber, 1) \
/* ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Call]] case */ \ /* ES #sec-number-constructor */ \
TFJ(NumberConstructor, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ TFJ(NumberConstructor, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 section 20.1.1.1 Number ( [ value ] ) for the [[Construct]] case */ \
TFJ(NumberConstructor_ConstructStub, \
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 #sec-number.isfinite */ \ /* ES6 #sec-number.isfinite */ \
TFJ(NumberIsFinite, 1, kNumber) \ TFJ(NumberIsFinite, 1, kNumber) \
/* ES6 #sec-number.isinteger */ \ /* ES6 #sec-number.isinteger */ \
......
...@@ -264,7 +264,6 @@ bool Builtins::IsLazy(int index) { ...@@ -264,7 +264,6 @@ bool Builtins::IsLazy(int index) {
case kInterpreterEntryTrampoline: case kInterpreterEntryTrampoline:
case kPromiseConstructorLazyDeoptContinuation: // https://crbug/v8/6786. case kPromiseConstructorLazyDeoptContinuation: // https://crbug/v8/6786.
case kProxyConstructor_ConstructStub: // https://crbug.com/v8/6787. case kProxyConstructor_ConstructStub: // https://crbug.com/v8/6787.
case kNumberConstructor_ConstructStub: // https://crbug.com/v8/6787.
case kTypedArrayConstructor_ConstructStub: // https://crbug.com/v8/6787. case kTypedArrayConstructor_ConstructStub: // https://crbug.com/v8/6787.
case kProxyConstructor: // https://crbug.com/v8/6787. case kProxyConstructor: // https://crbug.com/v8/6787.
case kRecordWrite: // https://crbug.com/chromium/765301. case kRecordWrite: // https://crbug.com/chromium/765301.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment