ES5 defines toJSON functions on a number of standard objects. For complete JSON support we need to implement these.
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
Created attachment 31634 [details] Support Date.toJSON
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
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