Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: src/builtins.cc

Issue 2126453002: [intrinsic] Drop the %_ValueOf intrinsic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix noi18n build (narf) Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins.h ('k') | src/code-stub-assembler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index e53c168113768301b761227651b4e27099423198..02a700574578e08a0deca80bdbddc6ea544be78e 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -2243,6 +2243,229 @@ BUILTIN(JsonStringify) {
}
// -----------------------------------------------------------------------------
+// ES6 section 20.1 Number Objects
+
+// ES6 section 20.1.3.2 Number.prototype.toExponential ( fractionDigits )
+BUILTIN(NumberPrototypeToExponential) {
+ HandleScope scope(isolate);
+ Handle<Object> value = args.at<Object>(0);
+ Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1);
+
+ // Unwrap the receiver {value}.
+ if (value->IsJSValue()) {
+ value = handle(Handle<JSValue>::cast(value)->value(), isolate);
+ }
+ if (!value->IsNumber()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewTypeError(MessageTemplate::kNotGeneric,
+ isolate->factory()->NewStringFromAsciiChecked(
+ "Number.prototype.toExponential")));
+ }
+ double const value_number = value->Number();
+
+ // Convert the {fraction_digits} to an integer first.
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits));
+ double const fraction_digits_number = fraction_digits->Number();
+
+ if (std::isnan(value_number)) return isolate->heap()->nan_string();
+ if (std::isinf(value_number)) {
+ return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
+ : isolate->heap()->infinity_string();
+ }
+ if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewRangeError(MessageTemplate::kNumberFormatRange,
+ isolate->factory()->NewStringFromAsciiChecked(
+ "toExponential()")));
+ }
+ int const f = args.atOrUndefined(isolate, 1)->IsUndefined(isolate)
+ ? -1
+ : static_cast<int>(fraction_digits_number);
+ char* const str = DoubleToExponentialCString(value_number, f);
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
+// ES6 section 20.1.3.3 Number.prototype.toFixed ( fractionDigits )
+BUILTIN(NumberPrototypeToFixed) {
+ HandleScope scope(isolate);
+ Handle<Object> value = args.at<Object>(0);
+ Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1);
+
+ // Unwrap the receiver {value}.
+ if (value->IsJSValue()) {
+ value = handle(Handle<JSValue>::cast(value)->value(), isolate);
+ }
+ if (!value->IsNumber()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewTypeError(MessageTemplate::kNotGeneric,
+ isolate->factory()->NewStringFromAsciiChecked(
+ "Number.prototype.toFixed")));
+ }
+ double const value_number = value->Number();
+
+ // Convert the {fraction_digits} to an integer first.
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits));
+ double const fraction_digits_number = fraction_digits->Number();
+
+ // Check if the {fraction_digits} are in the supported range.
+ if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewRangeError(MessageTemplate::kNumberFormatRange,
+ isolate->factory()->NewStringFromAsciiChecked(
+ "toFixed() digits")));
+ }
+
+ if (std::isnan(value_number)) return isolate->heap()->nan_string();
+ if (std::isinf(value_number)) {
+ return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
+ : isolate->heap()->infinity_string();
+ }
+ char* const str = DoubleToFixedCString(
+ value_number, static_cast<int>(fraction_digits_number));
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
+// ES6 section 20.1.3.4 Number.prototype.toLocaleString ( [ r1 [ , r2 ] ] )
+BUILTIN(NumberPrototypeToLocaleString) {
+ HandleScope scope(isolate);
+ Handle<Object> value = args.at<Object>(0);
+
+ // Unwrap the receiver {value}.
+ if (value->IsJSValue()) {
+ value = handle(Handle<JSValue>::cast(value)->value(), isolate);
+ }
+ if (!value->IsNumber()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewTypeError(MessageTemplate::kNotGeneric,
+ isolate->factory()->NewStringFromAsciiChecked(
+ "Number.prototype.toLocaleString")));
+ }
+
+ // Turn the {value} into a String.
+ return *isolate->factory()->NumberToString(value);
+}
+
+// ES6 section 20.1.3.5 Number.prototype.toPrecision ( precision )
+BUILTIN(NumberPrototypeToPrecision) {
+ HandleScope scope(isolate);
+ Handle<Object> value = args.at<Object>(0);
+ Handle<Object> precision = args.atOrUndefined(isolate, 1);
+
+ // Unwrap the receiver {value}.
+ if (value->IsJSValue()) {
+ value = handle(Handle<JSValue>::cast(value)->value(), isolate);
+ }
+ if (!value->IsNumber()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewTypeError(MessageTemplate::kNotGeneric,
+ isolate->factory()->NewStringFromAsciiChecked(
+ "Number.prototype.toPrecision")));
+ }
+ double const value_number = value->Number();
+
+ // If no {precision} was specified, just return ToString of {value}.
+ if (precision->IsUndefined(isolate)) {
+ return *isolate->factory()->NumberToString(value);
+ }
+
+ // Convert the {precision} to an integer first.
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, precision,
+ Object::ToInteger(isolate, precision));
+ double const precision_number = precision->Number();
+
+ if (std::isnan(value_number)) return isolate->heap()->nan_string();
+ if (std::isinf(value_number)) {
+ return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
+ : isolate->heap()->infinity_string();
+ }
+ if (precision_number < 1.0 || precision_number > 21.0) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewRangeError(MessageTemplate::kToPrecisionFormatRange));
+ }
+ char* const str = DoubleToPrecisionCString(
+ value_number, static_cast<int>(precision_number));
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
+// ES6 section 20.1.3.6 Number.prototype.toString ( [ radix ] )
+BUILTIN(NumberPrototypeToString) {
+ HandleScope scope(isolate);
+ Handle<Object> value = args.at<Object>(0);
+ Handle<Object> radix = args.atOrUndefined(isolate, 1);
+
+ // Unwrap the receiver {value}.
+ if (value->IsJSValue()) {
+ value = handle(Handle<JSValue>::cast(value)->value(), isolate);
+ }
+ if (!value->IsNumber()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewTypeError(MessageTemplate::kNotGeneric,
+ isolate->factory()->NewStringFromAsciiChecked(
+ "Number.prototype.toString")));
+ }
+ double const value_number = value->Number();
+
+ // If no {radix} was specified, just return ToString of {value}.
+ if (radix->IsUndefined(isolate)) {
+ return *isolate->factory()->NumberToString(value);
+ }
+
+ // Convert the {radix} to an integer first.
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, radix,
+ Object::ToInteger(isolate, radix));
+ double const radix_number = radix->Number();
+
+ // If {radix} is 10, just return ToString of {value}.
+ if (radix_number == 10.0) return *isolate->factory()->NumberToString(value);
+
+ // Make sure the {radix} is within the valid range.
+ if (radix_number < 2.0 || radix_number > 36.0) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate, NewRangeError(MessageTemplate::kToRadixFormatRange));
+ }
+
+ // Fast case where the result is a one character string.
+ if (IsUint32Double(value_number) && value_number < radix_number) {
+ // Character array used for conversion.
+ static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+ return *isolate->factory()->LookupSingleCharacterStringFromCode(
+ kCharTable[static_cast<uint32_t>(value_number)]);
+ }
+
+ // Slow case.
+ if (std::isnan(value_number)) return isolate->heap()->nan_string();
+ if (std::isinf(value_number)) {
+ return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
+ : isolate->heap()->infinity_string();
+ }
+ char* const str =
+ DoubleToRadixCString(value_number, static_cast<int>(radix_number));
+ Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
+ DeleteArray(str);
+ return *result;
+}
+
+// ES6 section 20.1.3.7 Number.prototype.valueOf ( )
+void Builtins::Generate_NumberPrototypeValueOf(CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ Node* result = assembler->ToThisValue(
+ context, receiver, PrimitiveType::kNumber, "Number.prototype.valueOf");
+ assembler->Return(result);
+}
+
+// -----------------------------------------------------------------------------
// ES6 section 20.2.2 Function Properties of the Math Object
// ES6 section - 20.2.2.1 Math.abs ( x )
@@ -3201,38 +3424,29 @@ 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();
-}
+void Builtins::Generate_BooleanPrototypeToString(CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
-// 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;
+ Node* value = assembler->ToThisValue(
+ context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.toString");
+ Node* result = assembler->LoadObjectField(value, Oddball::kToStringOffset);
+ assembler->Return(result);
}
+// ES6 section 19.3.3.3 Boolean.prototype.valueOf ( )
+void Builtins::Generate_BooleanPrototypeValueOf(CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ Node* result = assembler->ToThisValue(
+ context, receiver, PrimitiveType::kBoolean, "Boolean.prototype.valueOf");
+ assembler->Return(result);
+}
// -----------------------------------------------------------------------------
// ES6 section 24.2 DataView Objects
@@ -4769,6 +4983,17 @@ BUILTIN(AsyncFunctionConstructor) {
return *func;
}
+// ES6 19.1.3.6 Object.prototype.toString
+BUILTIN(ObjectProtoToString) {
+ HandleScope scope(isolate);
+ Handle<Object> object = args.at<Object>(0);
+ RETURN_RESULT_OR_FAILURE(isolate,
+ Object::ObjectProtoToString(isolate, object));
+}
+
+// -----------------------------------------------------------------------------
+// ES6 section 19.4 Symbol Objects
+
// ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case.
BUILTIN(SymbolConstructor) {
HandleScope scope(isolate);
@@ -4791,13 +5016,44 @@ BUILTIN(SymbolConstructor_ConstructStub) {
isolate->factory()->Symbol_string()));
}
+// ES6 section 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )
+void Builtins::Generate_SymbolPrototypeToPrimitive(
+ CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(4);
+
+ Node* result =
+ assembler->ToThisValue(context, receiver, PrimitiveType::kSymbol,
+ "Symbol.prototype [ @@toPrimitive ]");
+ assembler->Return(result);
+}
+
+// ES6 section 19.4.3.2 Symbol.prototype.toString ( )
+void Builtins::Generate_SymbolPrototypeToString(CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
-// ES6 19.1.3.6 Object.prototype.toString
-BUILTIN(ObjectProtoToString) {
- HandleScope scope(isolate);
- Handle<Object> object = args.at<Object>(0);
- RETURN_RESULT_OR_FAILURE(isolate,
- Object::ObjectProtoToString(isolate, object));
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ Node* value = assembler->ToThisValue(
+ context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.toString");
+ Node* result =
+ assembler->CallRuntime(Runtime::kSymbolDescriptiveString, context, value);
+ assembler->Return(result);
+}
+
+// ES6 section 19.4.3.3 Symbol.prototype.valueOf ( )
+void Builtins::Generate_SymbolPrototypeValueOf(CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ Node* result = assembler->ToThisValue(
+ context, receiver, PrimitiveType::kSymbol, "Symbol.prototype.valueOf");
+ assembler->Return(result);
}
// -----------------------------------------------------------------------------
@@ -5270,7 +5526,19 @@ void Builtins::Generate_StringPrototypeCharCodeAt(
assembler->Return(result);
}
-// ES6 section 21.1.3.25 String.prototype.trim ()
+// ES6 section 21.1.3.25 String.prototype.toString ()
+void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ Node* result = assembler->ToThisValue(
+ context, receiver, PrimitiveType::kString, "String.prototype.toString");
+ assembler->Return(result);
+}
+
+// ES6 section 21.1.3.27 String.prototype.trim ()
BUILTIN(StringPrototypeTrim) {
HandleScope scope(isolate);
TO_THIS_STRING(string, "String.prototype.trim");
@@ -5291,6 +5559,18 @@ BUILTIN(StringPrototypeTrimRight) {
return *String::Trim(string, String::kTrimRight);
}
+// ES6 section 21.1.3.28 String.prototype.valueOf ( )
+void Builtins::Generate_StringPrototypeValueOf(CodeStubAssembler* assembler) {
+ typedef compiler::Node Node;
+
+ Node* receiver = assembler->Parameter(0);
+ Node* context = assembler->Parameter(3);
+
+ Node* result = assembler->ToThisValue(
+ context, receiver, PrimitiveType::kString, "String.prototype.valueOf");
+ assembler->Return(result);
+}
+
// -----------------------------------------------------------------------------
// ES6 section 21.1 ArrayBuffer Objects
« no previous file with comments | « src/builtins.h ('k') | src/code-stub-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698