Bug 142829 - [ES6] Implement Symbol.unscopables
Summary: [ES6] Implement Symbol.unscopables
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-18 11:10 PDT by Yusuke Suzuki
Modified: 2015-04-01 02:31 PDT (History)
6 users (show)

See Also:


Attachments
Patch (10.50 KB, patch)
2015-03-19 01:42 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (10.68 KB, patch)
2015-03-19 01:47 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (12.64 KB, patch)
2015-03-22 04:44 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (13.61 KB, patch)
2015-03-31 14:32 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (13.62 KB, patch)
2015-03-31 14:34 PDT, Yusuke Suzuki
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2015-03-18 11:10:08 PDT
Implement Symbol.unscopables support in with scope.
It allow runtime to expose some generic name methods like `values`.
Comment 1 Yusuke Suzuki 2015-03-19 01:42:58 PDT
Created attachment 249026 [details]
Patch
Comment 2 Yusuke Suzuki 2015-03-19 01:47:46 PDT
Created attachment 249027 [details]
Patch
Comment 3 Yusuke Suzuki 2015-03-21 04:43:12 PDT
Could anyone take a look?
Comment 4 Joseph Pecoraro 2015-03-21 09:27:16 PDT
Comment on attachment 249027 [details]
Patch

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

Nifty!

> Source/JavaScriptCore/tests/stress/unscopables.js:25
> +        test(__proto__, Array.prototype);  // array's unscopbales.__proto__ is undefined => false.

Typo: unscopbales

> Source/JavaScriptCore/tests/stress/unscopables.js:47
> +        test(toString, "toString");  // object.toString is hidden by unscopables.toString.

Can we have an equivalent test where the unscopables object doesn't have the Object prototype? So: [Symbol.unscopables]: { Cocoa: false, Cappuccino: true, __proto__: null }. In which I think we would expect test(toString) to be Object.prototype.toString within this with block.
Comment 5 Yusuke Suzuki 2015-03-22 04:44:56 PDT
Created attachment 249193 [details]
Patch
Comment 6 Yusuke Suzuki 2015-03-22 04:45:41 PDT
Comment on attachment 249027 [details]
Patch

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

Added comments and updated the patch.

>> Source/JavaScriptCore/tests/stress/unscopables.js:25
>> +        test(__proto__, Array.prototype);  // array's unscopbales.__proto__ is undefined => false.
> 
> Typo: unscopbales

Oops! Thank you.
Fixed.

>> Source/JavaScriptCore/tests/stress/unscopables.js:47
>> +        test(toString, "toString");  // object.toString is hidden by unscopables.toString.
> 
> Can we have an equivalent test where the unscopables object doesn't have the Object prototype? So: [Symbol.unscopables]: { Cocoa: false, Cappuccino: true, __proto__: null }. In which I think we would expect test(toString) to be Object.prototype.toString within this with block.

Sounds very nice. Added.
Comment 7 Yusuke Suzuki 2015-03-31 14:32:39 PDT
Created attachment 249852 [details]
Patch
Comment 8 Yusuke Suzuki 2015-03-31 14:34:21 PDT
Created attachment 249853 [details]
Patch
Comment 9 Geoffrey Garen 2015-03-31 16:27:44 PDT
Comment on attachment 249853 [details]
Patch

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

r=me

> Source/JavaScriptCore/runtime/JSScope.cpp:161
> +            if (scope->type() != WithScopeType)
> +                return object;
> +
> +            JSValue unscopables = object->get(exec, exec->propertyNames().unscopablesSymbol);
> +            if (exec->hadException())
> +                return object;
> +            if (!unscopables.isObject())
> +                return object;
> +            JSValue blocked = jsCast<JSObject*>(unscopables)->get(exec, ident);
> +            if (exec->hadException())
> +                return object;
> +            if (!blocked.toBoolean(exec))
> +                return object;
> +            ASSERT_WITH_MESSAGE(!exec->hadException(), "JSValue::toBoolean does not raise any errors.");

It would be nice to factor this code into a static inline helper function named "isUnscopable".
Comment 10 Yusuke Suzuki 2015-04-01 02:04:01 PDT
Committed r182225: <http://trac.webkit.org/changeset/182225>
Comment 11 Yusuke Suzuki 2015-04-01 02:31:07 PDT
Comment on attachment 249853 [details]
Patch

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

Thank you for your review! I've landed it with fix.

>> Source/JavaScriptCore/runtime/JSScope.cpp:161
>> +            ASSERT_WITH_MESSAGE(!exec->hadException(), "JSValue::toBoolean does not raise any errors.");
> 
> It would be nice to factor this code into a static inline helper function named "isUnscopable".

OK! I've extracted it to isUnscopable function.