Changeset 44931 in webkit
- Timestamp:
- Jun 21, 2009 11:35:51 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r44929 r44931 1 2009-06-21 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Darin Adler. 4 5 Bug 26592: Support standard toJSON functions 6 <https://bugs.webkit.org/show_bug.cgi?id=26592> 7 8 Add support for the standard Date.toJSON function. 9 10 * runtime/DatePrototype.cpp: 11 (JSC::dateProtoFuncToJSON): 12 1 13 2009-06-21 Oliver Hunt <oliver@apple.com> 2 14 -
trunk/JavaScriptCore/runtime/CommonIdentifiers.h
r44813 r44931 60 60 macro(toExponential) \ 61 61 macro(toFixed) \ 62 macro(toISOString) \ 62 63 macro(toJSON) \ 63 64 macro(toLocaleString) \ -
trunk/JavaScriptCore/runtime/DatePrototype.cpp
r44929 r44931 115 115 static JSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState*, JSObject*, JSValue, const ArgList&); 116 116 static JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState*, JSObject*, JSValue, const ArgList&); 117 118 static JSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState*, JSObject*, JSValue, const ArgList&); 117 119 118 120 } … … 388 390 setYear dateProtoFuncSetYear DontEnum|Function 1 389 391 getYear dateProtoFuncGetYear DontEnum|Function 0 392 toJSON dateProtoFuncToJSON DontEnum|Function 0 390 393 @end 391 394 */ … … 1077 1080 } 1078 1081 1082 JSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) 1083 { 1084 JSObject* object = thisValue.toThisObject(exec); 1085 if (exec->hadException()) 1086 return jsNull(); 1087 1088 JSValue toISOValue = object->get(exec, exec->globalData().propertyNames->toISOString); 1089 if (exec->hadException()) 1090 return jsNull(); 1091 1092 CallData callData; 1093 CallType callType = toISOValue.getCallData(callData); 1094 if (callType == CallTypeNone) 1095 return throwError(exec, TypeError, "toISOString is not a function"); 1096 1097 JSValue result = call(exec, asObject(toISOValue), callType, callData, object, exec->emptyList()); 1098 if (exec->hadException()) 1099 return jsNull(); 1100 if (result.isObject()) 1101 return throwError(exec, TypeError, "toISOString did not return a primitive value"); 1102 return result; 1103 } 1104 1079 1105 } // namespace JSC -
trunk/LayoutTests/ChangeLog
r44929 r44931 1 2009-06-21 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Darin Adler. 4 5 Bug 26592: Support standard toJSON functions 6 7 Add tests of Date.toJSON. 8 9 * fast/js/JSON-stringify-expected.txt: 10 * fast/js/resources/JSON-stringify.js: 11 (createTests.result): 12 (createTests.result.push.): 13 1 14 2009-06-21 Oliver Hunt <oliver@apple.com> 2 15 -
trunk/LayoutTests/fast/js/JSON-stringify-expected.txt
r44813 r44931 1 function (jsonObject) { 2 return jsonObject.stringify(new Date(0)); 3 } 4 PASS tests[i](nativeJSON) is tests[i](JSON) 5 function (jsonObject) { 6 return jsonObject.stringify({toJSON: Date.prototype.toJSON}); 7 } 8 PASS tests[i](nativeJSON) threw exception TypeError: toISOString is not a function. 9 function (jsonObject) { 10 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString: function(){ return "custom toISOString"; }}); 11 } 12 PASS tests[i](nativeJSON) is tests[i](JSON) 1 13 function (jsonObject) { 2 14 return jsonObject.stringify({get Foo() { return "bar"; }}); -
trunk/LayoutTests/fast/js/resources/JSON-stringify.js
r44813 r44931 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(new Date(0)); 10 }); 11 result.push(function(jsonObject){ 12 return jsonObject.stringify({toJSON: Date.prototype.toJSON}); 13 }); 14 result[result.length - 1].throws = true; 15 result.push(function(jsonObject){ 16 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString: function(){ return "custom toISOString"; }}); 17 }); 18 result.push(function(jsonObject){ 19 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString: function(){ return {}; }}); 20 }); 21 result[result.length - 1].throws = true; 22 result.push(function(jsonObject){ 23 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString: function(){ throw "An exception"; }}); 24 }); 25 result[result.length - 1].throws = true; 26 result.push(function(jsonObject){ 27 var d = new Date(0); 28 d.toISOString = null; 29 return jsonObject.stringify(d); 30 }); 31 result[result.length - 1].throws = true; 32 result.push(function(jsonObject){ 33 var d = new Date(0); 34 d.toJSON = undefined; 35 return jsonObject.stringify(d); 36 }); 8 37 result.push(function(jsonObject){ 9 38 return jsonObject.stringify({get Foo() { return "bar"; }});
Note: See TracChangeset
for help on using the changeset viewer.