Changeset 201674 in webkit


Ignore:
Timestamp:
Jun 3, 2016 6:08:27 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

JSON.stringify replacer function calls with numeric array indices
https://bugs.webkit.org/show_bug.cgi?id=158262
Source/JavaScriptCore:

rdar://problem/26613876

Patch by Benjamin Poulain <bpoulain@apple.com> on 2016-06-03
Reviewed by Saam Barati.

The spec of SerializeJSONArray is pretty clear that the index
should be transformed into a string before calling SerializeJSONProperty.
See http://www.ecma-international.org/ecma-262/6.0/#sec-serializejsonarray

  • runtime/JSONObject.cpp:

(JSC::PropertyNameForFunctionCall::value):

LayoutTests:

Patch by Benjamin Poulain <bpoulain@apple.com> on 2016-06-03
Reviewed by Saam Barati.

  • js/JSON-stringify-exposes-array-indices-as-strings-expected.txt: Added.
  • js/JSON-stringify-exposes-array-indices-as-strings.html: Added.
  • js/script-tests/JSON-stringify-exposes-array-indices-as-strings.js: Added.

(replacer):
(testObject.toJSON):
(toJSONArrayHelper):

  • js/resources/JSON-stringify.js:
  • js/dom/JSON-stringify-expected.txt:

Update the test results for the native implementation.

Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201667 r201674  
     12016-06-03  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        JSON.stringify replacer function calls with numeric array indices
     4        https://bugs.webkit.org/show_bug.cgi?id=158262
     5
     6        Reviewed by Saam Barati.
     7
     8        * js/JSON-stringify-exposes-array-indices-as-strings-expected.txt: Added.
     9        * js/JSON-stringify-exposes-array-indices-as-strings.html: Added.
     10        * js/script-tests/JSON-stringify-exposes-array-indices-as-strings.js: Added.
     11        (replacer):
     12        (testObject.toJSON):
     13        (toJSONArrayHelper):
     14        * js/resources/JSON-stringify.js:
     15        * js/dom/JSON-stringify-expected.txt:
     16        Update the test results for the native implementation.
     17
    1182016-06-03  Ryosuke Niwa  <rniwa@webkit.org>
    219
  • trunk/LayoutTests/js/dom/JSON-stringify-expected.txt

    r187016 r201674  
    148148        return allString;
    149149    }
    150 PASS tests[i](nativeJSON) is tests[i](JSON)
     150PASS tests[i](nativeJSON) is tests[i].expected
    151151function (jsonObject){
    152152        var allString = true;
  • trunk/LayoutTests/js/resources/JSON-stringify.js

    r187016 r201674  
    145145        return allString;
    146146    });
     147    result[result.length - 1].expected = true;
    147148    result.push(function(jsonObject){
    148149        var allString = true;
     
    347348        return replaceTracker;
    348349    });
    349     result[result.length - 1].expected = '(string)[1,2,3,null,null,null,4,5,6];0(number)1;1(number)2;2(number)3;3(number)undefined;4(number)undefined;5(number)undefined;6(number)4;7(number)5;8(number)6;'
     350    result[result.length - 1].expected = '(string)[1,2,3,null,null,null,4,5,6];0(string)1;1(string)2;2(string)3;3(string)undefined;4(string)undefined;5(string)undefined;6(string)4;7(string)5;8(string)6;'
    350351    result.push(function(jsonObject){
    351352        replaceTracker = "";
     
    428429        return cycleTracker;
    429430    });
    430     result[result.length - 1].expected = "0(number):[object Object]first, -> exception";
     431    result[result.length - 1].expected = "0(string):[object Object]first, -> exception";
    431432    function createArray(len, o) { var r = []; for (var i = 0; i < len; i++) r[i] = o; return r; }
    432433    var getterCalls;
  • trunk/Source/JavaScriptCore/ChangeLog

    r201672 r201674  
     12016-06-03  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        JSON.stringify replacer function calls with numeric array indices
     4        https://bugs.webkit.org/show_bug.cgi?id=158262
     5        rdar://problem/26613876
     6
     7        Reviewed by Saam Barati.
     8
     9        The spec of SerializeJSONArray is pretty clear that the index
     10        should be transformed into a string before calling SerializeJSONProperty.
     11        See http://www.ecma-international.org/ecma-262/6.0/#sec-serializejsonarray
     12
     13        * runtime/JSONObject.cpp:
     14        (JSC::PropertyNameForFunctionCall::value):
     15
    1162016-06-03  Saam barati  <sbarati@apple.com>
    217
  • trunk/Source/JavaScriptCore/runtime/JSONObject.cpp

    r201448 r201674  
    201201        if (m_identifier)
    202202            m_value = jsString(exec, m_identifier->string());
    203         else
    204             m_value = jsNumber(m_number);
     203        else {
     204            VM& vm = exec->vm();
     205            if (m_number <= 9)
     206                return vm.smallStrings.singleCharacterString(m_number + '0');
     207            m_value = jsNontrivialString(&vm, vm.numericStrings.add(m_number));
     208        }
    205209    }
    206210    return m_value;
Note: See TracChangeset for help on using the changeset viewer.