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

Unified Diff: src/v8natives.js

Issue 93066: Built-in JSON support (Closed)
Patch Set: Created 11 years, 8 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
« src/objects.h ('K') | « src/string.js ('k') | test/mjsunit/json.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 9772e2f0c28d27bd433dffa03c2a663ed4ea4f09..9ed6558473e92e206ebc3d41415b3446c444e671 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -312,13 +312,19 @@ function BooleanValueOf() {
}
+function BooleanToJSON(key) {
+ return CheckJSONPrimitive(this.valueOf());
+}
+
+
// ----------------------------------------------------------------------------
function SetupBoolean() {
InstallFunctions($Boolean.prototype, DONT_ENUM, $Array(
"toString", BooleanToString,
- "valueOf", BooleanValueOf
+ "valueOf", BooleanValueOf,
+ "toJSON", BooleanToJSON
));
}
@@ -418,6 +424,18 @@ function NumberToPrecision(precision) {
}
+function CheckJSONPrimitive(val) {
+ if (!IsPrimitive(val))
+ throw MakeTypeError('result_not_primitive', ['toJSON', val]);
+ return val;
+}
+
+
+function NumberToJSON(key) {
+ return CheckJSONPrimitive(this.valueOf());
+}
+
+
// ----------------------------------------------------------------------------
function SetupNumber() {
@@ -455,7 +473,8 @@ function SetupNumber() {
"valueOf", NumberValueOf,
"toFixed", NumberToFixed,
"toExponential", NumberToExponential,
- "toPrecision", NumberToPrecision
+ "toPrecision", NumberToPrecision,
+ "toJSON", NumberToJSON
));
}
« src/objects.h ('K') | « src/string.js ('k') | test/mjsunit/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698