Bug 142829

Summary: [ES6] Implement Symbol.unscopables
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: barraclough, benjamin, fpizlo, ggaren, joepeck, mark.lam
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch ggaren: review+

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.