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

Unified Diff: src/date.js

Issue 1306303003: [es6] Implement spec compliant ToPrimitive in the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Michis comments. Created 5 years, 4 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/contexts.h ('k') | src/debug/debug.cc » ('j') | src/objects.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/date.js
diff --git a/src/date.js b/src/date.js
index 2be8bcb220a7f3ed91ea1fb6943fa79398d5e4a7..44d2f4df1639044f19958d914c858bdc87760508 100644
--- a/src/date.js
+++ b/src/date.js
@@ -364,6 +364,21 @@ function DateToLocaleTimeString() {
}
+// 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint )
+function DateToPrimitive(hint) {
+ if (!IS_SPEC_OBJECT(this)) {
+ throw MakeTypeError(kIncompatibleMethodReceiver,
+ "Date.prototype [ @@toPrimitive ]", this);
+ }
+ if (hint === "default") {
+ hint = "string";
+ } else if (hint !== "number" && hint !== "string") {
+ throw MakeTypeError(kInvalidHint, hint);
+ }
+ return %OrdinaryToPrimitive(this, hint);
+}
+
+
// ECMA 262 - 15.9.5.8
function DateValueOf() {
CHECK_DATE(this);
@@ -777,9 +792,10 @@ function DateToISOString() {
}
+// 20.3.4.37 Date.prototype.toJSON ( key )
function DateToJSON(key) {
var o = TO_OBJECT(this);
- var tv = $defaultNumber(o);
+ var tv = TO_PRIMITIVE_NUMBER(o);
if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) {
return null;
}
@@ -831,6 +847,9 @@ utils.InstallFunctions(GlobalDate, DONT_ENUM, [
// Set up non-enumerable constructor property of the Date prototype object.
%AddNamedProperty(GlobalDate.prototype, "constructor", GlobalDate, DONT_ENUM);
+utils.SetFunctionName(DateToPrimitive, symbolToPrimitive);
+%AddNamedProperty(GlobalDate.prototype, symbolToPrimitive, DateToPrimitive,
+ DONT_ENUM | READ_ONLY);
// Set up non-enumerable functions of the Date prototype object and
// set their names.
« no previous file with comments | « src/contexts.h ('k') | src/debug/debug.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698