Commit 6de9b9ce authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Migrate the leftover Boolean setup to C++.

There's no point in having the setup or the toString/valueOf methods in
JavaScript. The full setup can be done during bootstrapping when the
Boolean constructor is created, and the prototype methods don't benefit
from JS + %_ at all.

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/1701273003

Cr-Commit-Position: refs/heads/master@{#34068}
parent 305a36e0
......@@ -1244,6 +1244,22 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
boolean_fun->shared()->set_length(1);
InstallWithIntrinsicDefaultProto(isolate, boolean_fun,
Context::BOOLEAN_FUNCTION_INDEX);
// Create the %BooleanPrototype%
Handle<JSValue> prototype =
Handle<JSValue>::cast(factory->NewJSObject(boolean_fun, TENURED));
prototype->set_value(isolate->heap()->false_value());
Accessors::FunctionSetPrototype(boolean_fun, prototype).Assert();
// Install the "constructor" property on the {prototype}.
JSObject::AddProperty(prototype, factory->constructor_string(), boolean_fun,
DONT_ENUM);
// Install the Boolean.prototype methods.
SimpleInstallFunction(prototype, "toString",
Builtins::kBooleanPrototypeToString, 0, false);
SimpleInstallFunction(prototype, "valueOf",
Builtins::kBooleanPrototypeValueOf, 0, false);
}
{ // --- S t r i n g ---
......
......@@ -2345,6 +2345,40 @@ BUILTIN(BooleanConstructor_ConstructStub) {
}
// ES6 section 19.3.3.2 Boolean.prototype.toString ( )
BUILTIN(BooleanPrototypeToString) {
HandleScope scope(isolate);
Handle<Object> receiver = args.receiver();
if (receiver->IsJSValue()) {
receiver = handle(Handle<JSValue>::cast(receiver)->value(), isolate);
}
if (!receiver->IsBoolean()) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Boolean.prototype.toString")));
}
return Handle<Oddball>::cast(receiver)->to_string();
}
// ES6 section 19.3.3.3 Boolean.prototype.valueOf ( )
BUILTIN(BooleanPrototypeValueOf) {
HandleScope scope(isolate);
Handle<Object> receiver = args.receiver();
if (receiver->IsJSValue()) {
receiver = handle(Handle<JSValue>::cast(receiver)->value(), isolate);
}
if (!receiver->IsBoolean()) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotGeneric,
isolate->factory()->NewStringFromAsciiChecked(
"Boolean.prototype.valueOf")));
}
return *receiver;
}
// -----------------------------------------------------------------------------
// ES6 section 20.3 Date Objects
......
......@@ -71,6 +71,8 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
\
V(BooleanConstructor, kNone) \
V(BooleanConstructor_ConstructStub, kTargetAndNewTarget) \
V(BooleanPrototypeToString, kNone) \
V(BooleanPrototypeValueOf, kNone) \
\
V(DateConstructor, kNone) \
V(DateConstructor_ConstructStub, kTargetAndNewTarget) \
......
......@@ -10,7 +10,6 @@
// Imports
var GlobalArray = global.Array;
var GlobalBoolean = global.Boolean;
var GlobalNumber = global.Number;
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
......@@ -878,44 +877,6 @@ utils.InstallFunctions(GlobalObject, DONT_ENUM, [
]);
// ----------------------------------------------------------------------------
// Boolean
function BooleanToString() {
// NOTE: Both Boolean objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262.
var b = this;
if (!IS_BOOLEAN(b)) {
if (!IS_BOOLEAN_WRAPPER(b)) {
throw MakeTypeError(kNotGeneric, 'Boolean.prototype.toString');
}
b = %_ValueOf(b);
}
return b ? 'true' : 'false';
}
function BooleanValueOf() {
// NOTE: Both Boolean objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262.
if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) {
throw MakeTypeError(kNotGeneric, 'Boolean.prototype.valueOf');
}
return %_ValueOf(this);
}
// ----------------------------------------------------------------------------
%FunctionSetPrototype(GlobalBoolean, new GlobalBoolean(false));
%AddNamedProperty(GlobalBoolean.prototype, "constructor", GlobalBoolean,
DONT_ENUM);
utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [
"toString", BooleanToString,
"valueOf", BooleanValueOf
]);
// ----------------------------------------------------------------------------
// Number
......
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