Bug 172419 - [JSC] Introduce @nakedConstructor to builtin JS
Summary: [JSC] Introduce @nakedConstructor to builtin JS
Status: RESOLVED DUPLICATE of bug 200898
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on: 172413
Blocks:
  Show dependency treegraph
 
Reported: 2017-05-20 13:30 PDT by Yusuke Suzuki
Modified: 2021-01-04 11:04 PST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 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;
}
Comment 1 Saam Barati 2017-05-21 13:01:28 PDT
Sounds like a good idea to me.
Comment 2 Alexey Shvayka 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 ***