Bug 190343

Summary: [JSC] JSON.stringify can accept call-with-no-arguments
Product: WebKit Reporter: Prasanneswar Ramachandran <rvspeswar>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Major CC: ews-watchlist, fpizlo, keith_miller, mark.lam, msaboff, saam, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch mark.lam: review+

Description Prasanneswar Ramachandran 2018-10-07 17:27:13 PDT
In JSON3 , they have used to stringify the non passing parameter as JSON. Stringify () so in json object omits this due to non argument count. Herewith need to add the dummy stringify for the JSON3 object. If added that JSON works as expected.
Comment 1 Radar WebKit Bug Importer 2018-10-07 17:27:37 PDT
<rdar://problem/45077333>
Comment 2 Yusuke Suzuki 2018-10-08 13:16:49 PDT
Can we have the code reproducing the issue?
Comment 3 Prasanneswar Ramachandran 2018-10-11 11:39:14 PDT
Hi,

Just save a cookies in the name of "{"times:{"time" :"0"}" with JSON3 library which already having in GITHUB  and stringify the mentioned JSON string . webkit enters with 0 argument count using the JSON3. 
Note:
If we dont use the JSON3 code in our testcode we can't reproduce the issue.
Comment 4 Prasanneswar Ramachandran 2018-10-11 11:43:35 PDT
Hi,

Just save a cookies in the name of "{"times:{"time" :"0"}" with JSON3 library which already having in GITHUB  and stringify the mentioned JSON string . webkit enters with 0 argument count using the JSON3. 
Note:
If we dont use the JSON3 code in our testcode we can't reproduce the issue.
Comment 5 Prasanneswar Ramachandran 2018-10-11 11:45:51 PDT
For this I have fixed as below mentioned

// ECMA-262 v5 15.12.3
EncodedJSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState* exec)
{
    if (!exec->argumentCount())
        return throwVMError(exec, createError(exec, ASCIILiteral("No input to stringify")));
    LocalScope scope(exec->globalData());
    Local<Unknown> value(exec->globalData(), exec->argument(0));
    Local<Unknown> replacer(exec->globalData(), exec->argument(1));
    Local<Unknown> space(exec->globalData(), exec->argument(2));
    return JSValue::encode(Stringifier(exec, replacer, space).stringify(value).get());
}

Modified:
========
// ECMA-262 v5 15.12.3
EncodedJSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState* exec)
{
    if (!exec->argumentCount()){
   LocalScope scope(exec->globalData());
    Local<Unknown> value(exec->globalData(), jsnull());
    Local<Unknown> replacer(exec->globalData(), jsnull());
    Local<Unknown> space(exec->globalData(), jsnull());
    return JSValue::encode(Stringifier(exec, replacer, space).stringify(value).get()

}
    LocalScope scope(exec->globalData());
    Local<Unknown> value(exec->globalData(), exec->argument(0));
    Local<Unknown> replacer(exec->globalData(), exec->argument(1));
    Local<Unknown> space(exec->globalData(), exec->argument(2));
    return JSValue::encode(Stringifier(exec, replacer, space).stringify(value).get());
}
Comment 6 Yusuke Suzuki 2018-10-13 08:29:57 PDT
Created attachment 352254 [details]
Patch
Comment 7 Mark Lam 2018-10-13 10:44:13 PDT
Comment on attachment 352254 [details]
Patch

r=me
Comment 8 Prasanneswar Ramachandran 2018-10-13 12:23:42 PDT
HI,

Yes this is correct and added as expected
Comment 9 Yusuke Suzuki 2018-10-15 06:48:16 PDT
Committed r237095: <https://trac.webkit.org/changeset/237095>