Bug 205983

Summary: Object.keys should throw if called on module namespace object with uninitialized binding
Product: WebKit Reporter: Alexey Shvayka <ashvayka>
Component: JavaScriptCoreAssignee: Alexey Shvayka <ashvayka>
Status: RESOLVED FIXED    
Severity: Trivial CC: caitp, commit-queue, ews-watchlist, keith_miller, mark.lam, msaboff, ross.kirsling, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
See Also: https://bugs.webkit.org/show_bug.cgi?id=189034
Attachments:
Description Flags
Patch
none
Patch none

Description Alexey Shvayka 2020-01-08 19:48:56 PST
ECMA262: call stack is quite deep, please see "info" meta of the test ↓
Test262: https://test262.report/browse/language/module-code/namespace/internals/object-keys-binding-uninit.js
Comment 1 Alexey Shvayka 2020-01-08 21:15:27 PST
Created attachment 387186 [details]
Patch
Comment 2 Alexey Shvayka 2020-01-08 21:25:15 PST
(In reply to Alexey Shvayka from comment #1)
> Created attachment 387186 [details]
> Patch

All credit goes to Caitlin Potter: this patch was nicely extracted from her solution to https://bugs.webkit.org/show_bug.cgi?id=189034.
Comment 3 Ross Kirsling 2020-01-09 09:58:16 PST
Comment on attachment 387186 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:1
> +2020-01-08  Caitlin Potter  <caitp@igalia.com>

I recently learned (from r253987) that it's valid to insert two authors separated by "and" here -- might make sense in a case like this?

> Source/JavaScriptCore/ChangeLog:10
> +        If [[OwnPropertyKeys]] method of module namespace object is called by
> +        Object.keys or for/in loop, it should invoke [[GetOwnProperty]] on
> +        every binding so a ReferenceError is thrown if the binding is uninitialized.

Wait, is [[OwnPropertyKeys]] directly relevant? It doesn't throw.

Seems like [[GetOwnProperty]] is called from EnumerableOwnPropertyNames *after* [[OwnPropertyKeys]], no?
https://tc39.es/ecma262/#sec-enumerableownpropertynames
Comment 4 Alexey Shvayka 2020-01-10 15:18:09 PST
Created attachment 387383 [details]
Patch

Add myself as co-author and fix method name in ChangeLog.
Comment 5 Alexey Shvayka 2020-01-10 15:31:37 PST
(In reply to Ross Kirsling from comment #3)
>
> I recently learned (from r253987) that it's valid to insert two authors
> separated by "and" here -- might make sense in a case like this?

Thank you for the tip.
I think it makes sense to add myself there for bookkeeping purposes or so I could be contacted regarding the change.

> Seems like [[GetOwnProperty]] is called from EnumerableOwnPropertyNames
> *after* [[OwnPropertyKeys]], no?
> https://tc39.es/ecma262/#sec-enumerableownpropertynames

Nice catch! Indeed, throwing occurs after [[OwnPropertyKeys]].
I've replaced [[OwnPropertyKeys]] with JSModuleNamespaceObject::getOwnPropertyNames.
Comment 6 Yusuke Suzuki 2020-01-10 15:31:54 PST
Comment on attachment 387383 [details]
Patch

r=me
Comment 7 Yusuke Suzuki 2020-01-10 15:32:53 PST
(In reply to Yusuke Suzuki from comment #6)
> Comment on attachment 387383 [details]
> Patch
> 
> r=me

Land it after resolving Ross's comment :)
Comment 8 Ross Kirsling 2020-01-10 15:35:08 PST
Comment on attachment 387383 [details]
Patch

Alexey's comment came after his new patch, so it should be okay :D
Comment 9 WebKit Commit Bot 2020-01-10 19:18:06 PST
Comment on attachment 387383 [details]
Patch

Clearing flags on attachment: 387383

Committed r254390: <https://trac.webkit.org/changeset/254390>
Comment 10 WebKit Commit Bot 2020-01-10 19:18:08 PST
All reviewed patches have been landed.  Closing bug.
Comment 11 Radar WebKit Bug Importer 2020-01-10 19:19:16 PST
<rdar://problem/58499079>