Changeset 47086 in webkit


Ignore:
Timestamp:
Aug 11, 2009 9:56:58 PM (15 years ago)
Author:
oliver@apple.com
Message:

Native JSON.stringify does not omit functions
https://bugs.webkit.org/show_bug.cgi?id=28117

Reviewed by Gavin Barraclough

Objects that are callable should be treated as undefined when
serialising to JSON.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r47062 r47086  
     12009-08-11  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        Native JSON.stringify does not omit functions
     6        https://bugs.webkit.org/show_bug.cgi?id=28117
     7
     8        Objects that are callable should be treated as undefined when
     9        serialising to JSON.
     10
     11        * runtime/JSONObject.cpp:
     12        (JSC::Stringifier::appendStringifiedValue):
     13
    1142009-08-11  Oliver Hunt  <oliver@apple.com>
    215
  • trunk/JavaScriptCore/runtime/JSONObject.cpp

    r47022 r47086  
    381381
    382382    JSObject* object = asObject(value);
     383
     384    CallData callData;
     385    if (object->getCallData(callData) != CallTypeNone) {
     386        if (holder->inherits(&JSArray::info)) {
     387            builder.append("null");
     388            return StringifySucceeded;
     389        }
     390        return StringifyFailedDueToUndefinedValue;
     391    }
    383392
    384393    // Handle cycle detection, and put the holder on the stack.
  • trunk/LayoutTests/ChangeLog

    r47083 r47086  
     12009-08-11  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        Native JSON.stringify does not omit functions
     6        https://bugs.webkit.org/show_bug.cgi?id=28117
     7
     8        Test serialisation of function objects.
     9
     10        * fast/js/JSON-stringify-expected.txt:
     11        * fast/js/JSON-stringify-replacer-expected.txt:
     12        * fast/js/resources/JSON-stringify-replacer.js:
     13        * fast/js/resources/JSON-stringify.js:
     14        (createTests.result.push.):
     15
    1162009-08-11  Brady Eidson  <beidson@apple.com>
    217
  • trunk/LayoutTests/fast/js/JSON-stringify-expected.txt

    r46967 r47086  
    350350function (jsonObject) {
    351351        return jsonObject.stringify({a:{toJSON:function(){ return null; }}});
     352    }
     353PASS tests[i](nativeJSON) is tests[i](JSON)
     354function (jsonObject) {
     355        return jsonObject.stringify({a:{toJSON:function(){ return function(){}; }}});
     356    }
     357PASS tests[i](nativeJSON) is tests[i](JSON)
     358function (jsonObject) {
     359        return jsonObject.stringify({a:function(){}});
    352360    }
    353361PASS tests[i](nativeJSON) is tests[i](JSON)
  • trunk/LayoutTests/fast/js/JSON-stringify-replacer-expected.txt

    r46967 r47086  
    1212PASS JSON.stringify(object, returnUndefinedFor1) is '{"0":0,"2":2}'
    1313PASS JSON.stringify(array, returnUndefinedFor1) is '[0,null,2,null]'
     14PASS JSON.stringify(object, returnFunctionFor1) is '{"0":0,"2":2}'
     15PASS JSON.stringify(array, returnFunctionFor1) is '[0,null,2,null]'
    1416PASS JSON.stringify(object, returnNullFor1) is '{"0":0,"1":null,"2":2}'
    1517PASS JSON.stringify(array, returnNullFor1) is '[0,null,2,null]'
  • trunk/LayoutTests/fast/js/resources/JSON-stringify-replacer.js

    r46967 r47086  
    3434    return v;
    3535}
     36function returnFunctionFor1(k, v) {
     37    if (k == "1")
     38        return function(){};
     39    return v;
     40}
    3641function returnStringForUndefined(k, v) {
    3742    if (v === undefined)
     
    5257shouldBe("JSON.stringify(array, returnUndefinedFor1)", '\'[0,null,2,null]\'');
    5358
     59shouldBe("JSON.stringify(object, returnFunctionFor1)", '\'{"0":0,"2":2}\'');
     60shouldBe("JSON.stringify(array, returnFunctionFor1)", '\'[0,null,2,null]\'');
     61
    5462shouldBe("JSON.stringify(object, returnNullFor1)", '\'{"0":0,"1":null,"2":2}\'');
    5563shouldBe("JSON.stringify(array, returnNullFor1)", '\'[0,null,2,null]\'');
  • trunk/LayoutTests/fast/js/resources/JSON-stringify.js

    r44974 r47086  
    315315    result.push(function(jsonObject){
    316316        return jsonObject.stringify({a:{toJSON:function(){ return null; }}});
     317    });
     318    result.push(function(jsonObject){
     319        return jsonObject.stringify({a:{toJSON:function(){ return function(){}; }}});
     320    });
     321    result.push(function(jsonObject){
     322        return jsonObject.stringify({a:function(){}});
    317323    });
    318324    result.push(function(jsonObject){
Note: See TracChangeset for help on using the changeset viewer.