Bug 151501 - JSC Builtins should use safe array methods
Summary: JSC Builtins should use safe array methods
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-20 10:34 PST by youenn fablet
Modified: 2015-12-10 02:51 PST (History)
5 users (show)

See Also:


Attachments
Patch (7.92 KB, patch)
2015-11-20 10:49 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Adding tests (14.07 KB, patch)
2015-12-01 06:20 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Improving test (14.41 KB, patch)
2015-12-03 00:38 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2015-11-20 10:34:50 PST
Currently builtins are using push and shift directly, which can be modified by user scripts.
Comment 1 youenn fablet 2015-11-20 10:49:26 PST
Created attachment 265971 [details]
Patch
Comment 2 youenn fablet 2015-12-01 06:20:19 PST
Created attachment 266355 [details]
Adding tests
Comment 3 Xabier Rodríguez Calvar 2015-12-01 07:34:53 PST
Comment on attachment 266355 [details]
Adding tests

View in context: https://bugs.webkit.org/attachment.cgi?id=266355&action=review

> Source/JavaScriptCore/runtime/ArrayPrototype.cpp:100
> -    JSC_NATIVE_INTRINSIC_FUNCTION("push", arrayProtoFuncPush, DontEnum, 1, ArrayPushIntrinsic);
> +    JSC_NATIVE_INTRINSIC_FUNCTION(vm.propertyNames->builtinNames().pushPublicName(), arrayProtoFuncPush, DontEnum, 1, ArrayPushIntrinsic);
> +    JSC_NATIVE_INTRINSIC_FUNCTION(vm.propertyNames->builtinNames().pushPrivateName(), arrayProtoFuncPush, DontEnum | DontDelete | ReadOnly, 1, ArrayPushIntrinsic);

This makes me think even harder that we need to find a proper solution for this, as adding internal slots with the original function seems like a workaround and I am almost sure we are forgetting to fix something.

> LayoutTests/streams/streams-promises.html:160
> +    const ArrayPushBackup = Array.prototype.push;
> +    const ArrayShiftBackup = Array.prototype.shift;
> +
> +    function cleanTest() {
> +        Array.prototype.push = ArrayPushBackup;
> +        Array.prototype.shift = ArrayShiftBackup;
> +    }

I guess at some point it would be interesting to implement a setup and tear down for the tests.
Comment 4 Geoffrey Garen 2015-12-01 13:01:53 PST
Comment on attachment 266355 [details]
Adding tests

View in context: https://bugs.webkit.org/attachment.cgi?id=266355&action=review

> Source/JavaScriptCore/runtime/ArrayPrototype.cpp:103
> +    JSC_NATIVE_FUNCTION(vm.propertyNames->builtinNames().shiftPublicName(), arrayProtoFuncShift, DontEnum, 0);
> +    JSC_NATIVE_FUNCTION(vm.propertyNames->builtinNames().shiftPrivateName(), arrayProtoFuncShift, DontEnum | DontDelete | ReadOnly, 0);

Wrong function here.
Comment 5 youenn fablet 2015-12-02 13:14:36 PST
Comment on attachment 266355 [details]
Adding tests

View in context: https://bugs.webkit.org/attachment.cgi?id=266355&action=review

>> Source/JavaScriptCore/runtime/ArrayPrototype.cpp:100
>> +    JSC_NATIVE_INTRINSIC_FUNCTION(vm.propertyNames->builtinNames().pushPrivateName(), arrayProtoFuncPush, DontEnum | DontDelete | ReadOnly, 1, ArrayPushIntrinsic);
> 
> This makes me think even harder that we need to find a proper solution for this, as adding internal slots with the original function seems like a workaround and I am almost sure we are forgetting to fix something.

The latter is indeed worrying.

>> Source/JavaScriptCore/runtime/ArrayPrototype.cpp:103
>> +    JSC_NATIVE_FUNCTION(vm.propertyNames->builtinNames().shiftPrivateName(), arrayProtoFuncShift, DontEnum | DontDelete | ReadOnly, 0);
> 
> Wrong function here.

Can you be more explicit about what is wrong here?
Comment 6 Geoffrey Garen 2015-12-02 13:55:16 PST
Comment on attachment 266355 [details]
Adding tests

View in context: https://bugs.webkit.org/attachment.cgi?id=266355&action=review

>>> Source/JavaScriptCore/runtime/ArrayPrototype.cpp:103
>>> +    JSC_NATIVE_FUNCTION(vm.propertyNames->builtinNames().shiftPrivateName(), arrayProtoFuncShift, DontEnum | DontDelete | ReadOnly, 0);
>> 
>> Wrong function here.
> 
> Can you be more explicit about what is wrong here?

Oops. I take it back.
Comment 7 youenn fablet 2015-12-03 00:38:01 PST
Created attachment 266516 [details]
Improving test
Comment 8 youenn fablet 2015-12-03 00:41:56 PST
> > LayoutTests/streams/streams-promises.html:160
> > +    const ArrayPushBackup = Array.prototype.push;
> > +    const ArrayShiftBackup = Array.prototype.shift;
> > +
> > +    function cleanTest() {
> > +        Array.prototype.push = ArrayPushBackup;
> > +        Array.prototype.shift = ArrayShiftBackup;
> > +    }
> 
> I guess at some point it would be interesting to implement a setup and tear
> down for the tests.

Right.
I improved a bit the test as modifying Array.prototype.push is making testharness.js unhappy when cleanTest is not called or not called early enough.
Current version will mark test as failing if an assertion does not pass, which is better than timing out.
Comment 9 WebKit Commit Bot 2015-12-10 02:51:07 PST
Comment on attachment 266516 [details]
Improving test

Clearing flags on attachment: 266516

Committed r193899: <http://trac.webkit.org/changeset/193899>
Comment 10 WebKit Commit Bot 2015-12-10 02:51:11 PST
All reviewed patches have been landed.  Closing bug.