Bug 172419

Summary: [JSC] Introduce @nakedConstructor to builtin JS
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: ashvayka, saam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 172413    
Bug Blocks:    

Yusuke Suzuki
Reported 2017-05-20 13:30:50 PDT
I would like to introduce a new function annotation (like @globalPrivate), @nakedConstructor. If this annotation is attached, the function becomes constructor, but it does not create_this automatically. The function need to return an object constructed from this function. Of course, the function need to care about new.target. This is very useful for Map, Set, and Promise constructors. These constructors do some JS specific things. For example, Set constructor takes an iterable object as its argument. And perform iteration and add values to the constructed object. If we can write it in JS, it is very nice... In the case of Promise, promise will invoke executor function, (new Promise(executor)). Currently, we always invoke this function in a tricky way. If we can implement the Promise constructor like the following, it is quite nice. @nakedConstructor function Promise(executor) { 'use strict'; var promise = @constructPromise(new.target); // some initialization... executor(promise.resolve, promise.reject); return promise; }
Attachments
Saam Barati
Comment 1 2017-05-21 13:01:28 PDT
Sounds like a good idea to me.
Alexey Shvayka
Comment 2 2021-01-04 11:04:34 PST
(In reply to Yusuke Suzuki from comment #0) > I would like to introduce a new function annotation (like @globalPrivate), @nakedConstructor. > If this annotation is attached, the function becomes constructor, but it > does not create_this automatically. @nakedConstructor annotation was introduced in r249509. *** This bug has been marked as a duplicate of bug 200898 ***
Note You need to log in before you can comment on or make changes to this bug.