Bug 28752

Summary: this in JSON.parse reviver is the global object
Product: WebKit Reporter: Luke Smith <lsmith>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: oliver
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
URL: http://lucassmith.name/pub/browser_bugs/wk/reviver_this.html
Attachments:
Description Flags
Patch v1
none
Patch v1 barraclough: review+

Description Luke Smith 2009-08-26 15:40:38 PDT
ES 5 spec states that the Walk abstract function calls the reviver function's [[Call]] "passing holder as the this value"

Currently WebKit's JSON.parse implementation passes the global object as this.

Aside from the spec violation, this also prevents the reviver from creating additional properties on the object or referencing other properties of the current object for value determination during parse.  Any new properties created are added to the global object.

I noted this while reviewing my YUI examples for the JSON Utility (which defers to native implementations if present).
http://developer.yahoo.com/yui/examples/json/json_convert_values.html

Note: The page behaves correctly because it is either (if viewed before 9/2/09) using version 2.7.0 which is not leveraging native behavior , or it is (if viewed after 9/2/09) using version 2.8.0 and is configured NOT to use native behavior specifically because of this bug.
Comment 1 Oliver Hunt 2009-08-26 23:33:35 PDT
Created attachment 38658 [details]
Patch v1
Comment 2 Oliver Hunt 2009-08-26 23:48:54 PDT
Comment on attachment 38658 [details]
Patch v1

Sam mentioned some issues, and i realised there's an entire class of bug i had failed to notice.
Comment 3 Oliver Hunt 2009-08-27 00:59:24 PDT
Created attachment 38661 [details]
Patch v1
Comment 4 Gavin Barraclough 2009-08-27 01:37:00 PDT
Comment on attachment 38661 [details]
Patch v1

R+ with exception throw change from IRC.
Comment 5 Oliver Hunt 2009-08-27 01:39:58 PDT
Committed r47812
Comment 6 Mark Rowe (bdash) 2009-08-27 15:54:49 PDT
Should this now be closed?