<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>147133</bug_id>
          
          <creation_ts>2015-07-20 17:40:09 -0700</creation_ts>
          <short_desc>Add availability for InternalFunction to have JS implementation</short_desc>
          <delta_ts>2015-10-17 16:27:39 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>147183</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Yusuke Suzuki">ysuzuki</reporter>
          <assigned_to name="Yusuke Suzuki">ysuzuki</assigned_to>
          <cc>oliver</cc>
    
    <cc>saam</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1110849</commentid>
    <comment_count>0</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2015-07-20 17:40:09 -0700</bug_when>
    <thetext>Current Promise constructor is implemented as an InternalFunction which has C++ implementations.
But almost all processes are done in JS builtin&apos;s @initializePromise function.
And after issue 147051 is landed, we can write the whole Promise constructor code in JS.

I suggest enabling InternalFunction to have JS function implementation instead of just replacing Promise constructor with a Promise builtin JS function object because if we replace the current Promise constructor with the JS function simply, we cannot leverage the getStaticFunctionSlot (&amp; its system for materializing builtin functions lazily)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1111501</commentid>
    <comment_count>1</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2015-07-22 17:54:53 -0700</bug_when>
    <thetext>One problem is that, when just using the JS implemented Promise, the class info of the generated Promise becomes the usual JSFinalObject&apos;s info.
If we would like not to break the current

jsDynamicCast&lt;JSPromise*&gt;(promise)

and

promise.inherits(JSPromise::info())

We need to notify the class info into the ObjectAllocationProfile.
And at that time, we need to take care for DFG because DFG assumes that CreateThis results is always JSFinalObject.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112162</commentid>
    <comment_count>2</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2015-07-24 18:18:33 -0700</bug_when>
    <thetext>After considering the design, I think introducing a byte code that changes class info is better. This byte code can be emitted only within the builtin code. And it occurs structure transitions due to the class info change.

I&apos;m planning the following form.

constructor Promise(executor) {
    @classInfoTransition(this, &quot;Promise&quot;);
    ...

}

This will keep the classInfo = JSPromise::info and `jsDynamicCast&lt;JSPromise*&gt;(promise)` in C++ working. It&apos;s useful for C++ users.
One thing we need to take care is that the C++ class should not extend the fields from the JSFinalObject.

Changing / notifying the base class info to ObjectAllocationProfile in the derived function constructor is a little bit difficult I think. In the almost all cases, super() chain is the static. However, seeing the spec, I&apos;ve found

    Reflect.construct ( target, argumentsList [, newTarget] )
    // http://www.ecma-international.org/ecma-262/6.0/#sec-reflect.construct

can specify the newTarget even if the target is not related to the newTarget completely.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1134266</commentid>
    <comment_count>3</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2015-10-17 16:27:39 -0700</bug_when>
    <thetext>The problematic part is, DFG assumes that classInfo won&apos;t be changed.
For example, in the clobberize phase, we rely on the fact that classInfo won&apos;t be changed through transitions.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>