RESOLVED FIXED 26592
Support standard toJSON functions
https://bugs.webkit.org/show_bug.cgi?id=26592
Summary Support standard toJSON functions
Oliver Hunt
Reported 2009-06-21 16:16:45 PDT
ES5 defines toJSON functions on a number of standard objects. For complete JSON support we need to implement these.
Attachments
Support Date.toJSON (6.20 KB, patch)
2009-06-21 22:41 PDT, Oliver Hunt
darin: review+
Erik Arvidsson
Comment 1 2009-06-21 17:49:38 PDT
Note that Boolean.prototype.toJSON, Number.prototype.toJSON and String.prototype.toJSON have been deleted from the spec. See section "15.12.3 JSON.stringify" at http://wiki.ecmascript.org/lib/exe/fetch.php?id=es3.1%3Aes3.1_proposal_working_draft&cache=cache&media=es3.1:es5_candidate_errata_june_17.pdf
Oliver Hunt
Comment 2 2009-06-21 22:41:49 PDT
Created attachment 31634 [details] Support Date.toJSON
Darin Adler
Comment 3 2009-06-21 22:45:37 PDT
Comment on attachment 31634 [details] Support Date.toJSON > + JSValue toISOValue = object->get(exec, Identifier(exec, "toISOString")); Should we make toISOString a common identifier? > + if (!toISOValue.isObject()) > + return throwError(exec, TypeError, "toISOString is not a function"); > + > + JSObject* toISO = asObject(toISOValue); > + CallData callData; > + CallType callType = toISO->getCallData(callData); > + if (callType == CallTypeNone) > + return throwError(exec, TypeError, "toISOString is not a function"); You should just use the JSValue version of getCallData, which does the same thing as above. You could do the asObject() cast in the call. You should add a test case that returns a string wrapper, since that's an easy case to get wrong. r=me
Oliver Hunt
Comment 4 2009-06-21 23:36:10 PDT
Committing to http://svn.webkit.org/repository/webkit/trunk ... M JavaScriptCore/ChangeLog M JavaScriptCore/runtime/CommonIdentifiers.h M JavaScriptCore/runtime/DatePrototype.cpp M LayoutTests/ChangeLog M LayoutTests/fast/js/JSON-stringify-expected.txt M LayoutTests/fast/js/resources/JSON-stringify.js Committed r44931
Note You need to log in before you can comment on or make changes to this bug.