Changeset 44974 in webkit
- Timestamp:
- Jun 22, 2009 10:44:55 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r44968 r44974 1 2009-06-22 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Bug 26640: JSON.stringify needs to special case Boolean objects 6 <https://bugs.webkit.org/show_bug.cgi?id=26640> 7 8 Add special case handling of the Boolean object so we match current 9 ES5 errata. 10 11 * runtime/JSONObject.cpp: 12 (JSC::unwrapBoxedPrimitive): renamed from unwrapNumberOrString 13 (JSC::gap): 14 (JSC::Stringifier::appendStringifiedValue): 15 1 16 2009-06-22 Oliver Hunt <oliver@apple.com> 2 17 -
trunk/JavaScriptCore/runtime/JSONObject.cpp
r44968 r44974 27 27 #include "JSONObject.h" 28 28 29 #include "BooleanObject.h" 29 30 #include "Error.h" 30 31 #include "ExceptionHelpers.h" … … 120 121 // ------------------------------ helper functions -------------------------------- 121 122 122 static inline JSValue unwrap NumberOrString(JSValue value)123 static inline JSValue unwrapBoxedPrimitive(JSValue value) 123 124 { 124 125 if (!value.isObject()) 125 126 return value; 126 if (!asObject(value)->inherits(&NumberObject::info) && !asObject(value)->inherits(&StringObject::info) )127 if (!asObject(value)->inherits(&NumberObject::info) && !asObject(value)->inherits(&StringObject::info) && !asObject(value)->inherits(&BooleanObject::info)) 127 128 return value; 128 129 return static_cast<JSWrapperObject*>(asObject(value))->internalValue(); … … 131 132 static inline UString gap(JSValue space) 132 133 { 133 space = unwrap NumberOrString(space);134 space = unwrapBoxedPrimitive(space); 134 135 135 136 // If the space value is a number, create a gap string with that number of spaces. … … 356 357 } 357 358 359 value = unwrapBoxedPrimitive(value); 360 358 361 if (value.isBoolean()) { 359 362 builder.append(value.getBoolean() ? "true" : "false"); 360 363 return StringifySucceeded; 361 364 } 362 363 value = unwrapNumberOrString(value);364 365 365 366 UString stringValue; -
trunk/LayoutTests/ChangeLog
r44969 r44974 1 2009-06-22 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Bug 26640: JSON.stringify needs to special case Boolean objects 6 <https://bugs.webkit.org/show_bug.cgi?id=26640> 7 8 Add tests for serialisation of wrapped and unwrapped primitives. 9 10 * fast/js/JSON-stringify-expected.txt: 11 * fast/js/resources/JSON-stringify.js: 12 * fast/js/resources/json2-es5-compat.js: 13 Modify Str() to match ES5 errata 14 1 15 2009-06-22 Sam Weinig <sam@webkit.org> 2 16 -
trunk/LayoutTests/fast/js/JSON-stringify-expected.txt
r44935 r44974 1 function (jsonObject) { 2 return jsonObject.stringify(1); 3 } 4 PASS tests[i](nativeJSON) is tests[i](JSON) 5 function (jsonObject) { 6 return jsonObject.stringify(1.5); 7 } 8 PASS tests[i](nativeJSON) is tests[i](JSON) 9 function (jsonObject) { 10 return jsonObject.stringify(-1); 11 } 12 PASS tests[i](nativeJSON) is tests[i](JSON) 13 function (jsonObject) { 14 return jsonObject.stringify(-1.5); 15 } 16 PASS tests[i](nativeJSON) is tests[i](JSON) 17 function (jsonObject) { 18 return jsonObject.stringify(null); 19 } 20 PASS tests[i](nativeJSON) is tests[i](JSON) 21 function (jsonObject) { 22 return jsonObject.stringify("string"); 23 } 24 PASS tests[i](nativeJSON) is tests[i](JSON) 25 function (jsonObject) { 26 return jsonObject.stringify(new Number(0)); 27 } 28 PASS tests[i](nativeJSON) is tests[i](JSON) 29 function (jsonObject) { 30 return jsonObject.stringify(new Number(1)); 31 } 32 PASS tests[i](nativeJSON) is tests[i](JSON) 33 function (jsonObject) { 34 return jsonObject.stringify(new Number(1.5)); 35 } 36 PASS tests[i](nativeJSON) is tests[i](JSON) 37 function (jsonObject) { 38 return jsonObject.stringify(new Number(-1)); 39 } 40 PASS tests[i](nativeJSON) is tests[i](JSON) 41 function (jsonObject) { 42 return jsonObject.stringify(new Number(-1.5)); 43 } 44 PASS tests[i](nativeJSON) is tests[i](JSON) 45 function (jsonObject) { 46 return jsonObject.stringify(new String("a string object")); 47 } 48 PASS tests[i](nativeJSON) is tests[i](JSON) 49 function (jsonObject) { 50 return jsonObject.stringify(new Boolean(true)); 51 } 52 PASS tests[i](nativeJSON) is tests[i](JSON) 53 function (jsonObject) { 54 return jsonObject.stringify(new Boolean(false)); 55 } 56 PASS tests[i](nativeJSON) is tests[i](JSON) 57 function (jsonObject) { 58 return jsonObject.stringify(true); 59 } 60 PASS tests[i](nativeJSON) is tests[i](JSON) 61 function (jsonObject) { 62 return jsonObject.stringify(false); 63 } 64 PASS tests[i](nativeJSON) is tests[i](JSON) 1 65 function (jsonObject) { 2 66 return jsonObject.stringify(new Date(0)); -
trunk/LayoutTests/fast/js/resources/JSON-stringify.js
r44931 r44974 6 6 var complexObject = {a:"1", b:"2", c:"3", d:undefined, e:null, "":12, get f(){ return simpleArray; }, array: complexArray}; 7 7 var result = []; 8 result.push(function(jsonObject){ 9 return jsonObject.stringify(1); 10 }); 11 result.push(function(jsonObject){ 12 return jsonObject.stringify(1.5); 13 }); 14 result.push(function(jsonObject){ 15 return jsonObject.stringify(-1); 16 }); 17 result.push(function(jsonObject){ 18 return jsonObject.stringify(-1.5); 19 }); 20 result.push(function(jsonObject){ 21 return jsonObject.stringify(null); 22 }); 23 result.push(function(jsonObject){ 24 return jsonObject.stringify("string"); 25 }); 26 result.push(function(jsonObject){ 27 return jsonObject.stringify(new Number(0)); 28 }); 29 result.push(function(jsonObject){ 30 return jsonObject.stringify(new Number(1)); 31 }); 32 result.push(function(jsonObject){ 33 return jsonObject.stringify(new Number(1.5)); 34 }); 35 result.push(function(jsonObject){ 36 return jsonObject.stringify(new Number(-1)); 37 }); 38 result.push(function(jsonObject){ 39 return jsonObject.stringify(new Number(-1.5)); 40 }); 41 result.push(function(jsonObject){ 42 return jsonObject.stringify(new String("a string object")); 43 }); 44 result.push(function(jsonObject){ 45 return jsonObject.stringify(new Boolean(true)); 46 }); 47 result.push(function(jsonObject){ 48 return jsonObject.stringify(new Boolean(false)); 49 }); 50 result.push(function(jsonObject){ 51 return jsonObject.stringify(true); 52 }); 53 result.push(function(jsonObject){ 54 return jsonObject.stringify(false); 55 }); 8 56 result.push(function(jsonObject){ 9 57 return jsonObject.stringify(new Date(0)); -
trunk/LayoutTests/fast/js/resources/json2-es5-compat.js
r44550 r44974 179 179 f(this.getUTCMinutes()) + ':' + 180 180 f(this.getUTCSeconds()) + 'Z'; 181 };182 183 String.prototype.toJSON =184 Number.prototype.toJSON =185 Boolean.prototype.toJSON = function (key) {186 return this.valueOf();187 181 }; 188 182 } … … 250 244 // What happens next depends on the value's type. 251 245 246 if (value && ((typeof value) === "object")) { 247 if (value.constructor === String || value.constructor === Number || value.constructor === Boolean) 248 value = value.valueOf(); 249 } 250 252 251 switch (typeof value) { 253 252 case 'string':
Note: See TracChangeset
for help on using the changeset viewer.