WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED DUPLICATE of
bug 200898
172419
[JSC] Introduce @nakedConstructor to builtin JS
https://bugs.webkit.org/show_bug.cgi?id=172419
Summary
[JSC] Introduce @nakedConstructor to builtin JS
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
Add attachment
proposed patch, testcase, etc.
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.
Top of Page
Format For Printing
XML
Clone This Bug