Changeset 260321 in webkit


Ignore:
Timestamp:
Apr 18, 2020 2:13:58 PM (4 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Replace DFG NewPromise with NewInternalFieldObject
https://bugs.webkit.org/show_bug.cgi?id=210687

Reviewed by Saam Barati.

The feature of DFG::NewPromise can be implemented completely with DFG::NewInternalFieldObject. This reduces code duplication, and furthermore,
this offers Object Allocation Sinking support for free. This patch replaces DFG::NewPromise with DFG::NewInternalFieldObject and remove DFG::NewPromise
completely.

  • dfg/DFGAbstractInterpreterInlines.h:

(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::parseBlock):

  • dfg/DFGClobberize.h:

(JSC::DFG::clobberize):

  • dfg/DFGClobbersExitState.cpp:

(JSC::DFG::clobbersExitState):

  • dfg/DFGConstantFoldingPhase.cpp:

(JSC::DFG::ConstantFoldingPhase::foldConstants):

  • dfg/DFGDoesGC.cpp:

(JSC::DFG::doesGC):

  • dfg/DFGFixupPhase.cpp:

(JSC::DFG::FixupPhase::fixupNode):

  • dfg/DFGNode.h:

(JSC::DFG::Node::convertToNewInternalFieldObject):
(JSC::DFG::Node::convertToNewInternalFieldObjectWithInlineFields):
(JSC::DFG::Node::hasIsInternalPromise):
(JSC::DFG::Node::hasStructure):
(JSC::DFG::Node::convertToNewPromise): Deleted.

  • dfg/DFGNodeType.h:
  • dfg/DFGObjectAllocationSinkingPhase.cpp:
  • dfg/DFGPredictionPropagationPhase.cpp:
  • dfg/DFGSafeToExecute.h:

(JSC::DFG::safeToExecute):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileNewInternalFieldObject):
(JSC::DFG::SpeculativeJIT::compileNewPromise): Deleted.

  • dfg/DFGSpeculativeJIT.h:
  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGStoreBarrierInsertionPhase.cpp:
  • ftl/FTLCapabilities.cpp:

(JSC::FTL::canCompile):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileNode):
(JSC::FTL::DFG::LowerDFGToB3::compileNewInternalFieldObject):
(JSC::FTL::DFG::LowerDFGToB3::compileMaterializeNewInternalFieldObject):
(JSC::FTL::DFG::LowerDFGToB3::compileNewPromise): Deleted.

  • ftl/FTLOperations.cpp:

(JSC::FTL::operationPopulateObjectInOSR):
(JSC::FTL::operationMaterializeObjectInOSR):

  • runtime/JSInternalPromise.cpp:

(JSC::JSInternalPromise::createWithInitialValues):

  • runtime/JSInternalPromise.h:
  • runtime/JSPromise.cpp:

(JSC::JSPromise::createWithInitialValues):
(JSC::JSPromise::finishCreation):
(JSC::JSPromise::status const):
(JSC::JSPromise::result const):
(JSC::JSPromise::flags const):
(JSC::JSPromise::resolve):
(JSC::JSPromise::reject):
(JSC::JSPromise::rejectAsHandled):

  • runtime/JSPromise.h:

(JSC::JSPromise::initialValues):
(JSC::JSPromise::internalField const):
(JSC::JSPromise::internalField):

Location:
trunk/Source/JavaScriptCore
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r260314 r260321  
     12020-04-18  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Replace DFG NewPromise with NewInternalFieldObject
     4        https://bugs.webkit.org/show_bug.cgi?id=210687
     5
     6        Reviewed by Saam Barati.
     7
     8        The feature of DFG::NewPromise can be implemented completely with DFG::NewInternalFieldObject. This reduces code duplication, and furthermore,
     9        this offers Object Allocation Sinking support for free. This patch replaces DFG::NewPromise with DFG::NewInternalFieldObject and remove DFG::NewPromise
     10        completely.
     11
     12        * dfg/DFGAbstractInterpreterInlines.h:
     13        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
     14        * dfg/DFGByteCodeParser.cpp:
     15        (JSC::DFG::ByteCodeParser::parseBlock):
     16        * dfg/DFGClobberize.h:
     17        (JSC::DFG::clobberize):
     18        * dfg/DFGClobbersExitState.cpp:
     19        (JSC::DFG::clobbersExitState):
     20        * dfg/DFGConstantFoldingPhase.cpp:
     21        (JSC::DFG::ConstantFoldingPhase::foldConstants):
     22        * dfg/DFGDoesGC.cpp:
     23        (JSC::DFG::doesGC):
     24        * dfg/DFGFixupPhase.cpp:
     25        (JSC::DFG::FixupPhase::fixupNode):
     26        * dfg/DFGNode.h:
     27        (JSC::DFG::Node::convertToNewInternalFieldObject):
     28        (JSC::DFG::Node::convertToNewInternalFieldObjectWithInlineFields):
     29        (JSC::DFG::Node::hasIsInternalPromise):
     30        (JSC::DFG::Node::hasStructure):
     31        (JSC::DFG::Node::convertToNewPromise): Deleted.
     32        * dfg/DFGNodeType.h:
     33        * dfg/DFGObjectAllocationSinkingPhase.cpp:
     34        * dfg/DFGPredictionPropagationPhase.cpp:
     35        * dfg/DFGSafeToExecute.h:
     36        (JSC::DFG::safeToExecute):
     37        * dfg/DFGSpeculativeJIT.cpp:
     38        (JSC::DFG::SpeculativeJIT::compileNewInternalFieldObject):
     39        (JSC::DFG::SpeculativeJIT::compileNewPromise): Deleted.
     40        * dfg/DFGSpeculativeJIT.h:
     41        * dfg/DFGSpeculativeJIT32_64.cpp:
     42        (JSC::DFG::SpeculativeJIT::compile):
     43        * dfg/DFGSpeculativeJIT64.cpp:
     44        (JSC::DFG::SpeculativeJIT::compile):
     45        * dfg/DFGStoreBarrierInsertionPhase.cpp:
     46        * ftl/FTLCapabilities.cpp:
     47        (JSC::FTL::canCompile):
     48        * ftl/FTLLowerDFGToB3.cpp:
     49        (JSC::FTL::DFG::LowerDFGToB3::compileNode):
     50        (JSC::FTL::DFG::LowerDFGToB3::compileNewInternalFieldObject):
     51        (JSC::FTL::DFG::LowerDFGToB3::compileMaterializeNewInternalFieldObject):
     52        (JSC::FTL::DFG::LowerDFGToB3::compileNewPromise): Deleted.
     53        * ftl/FTLOperations.cpp:
     54        (JSC::FTL::operationPopulateObjectInOSR):
     55        (JSC::FTL::operationMaterializeObjectInOSR):
     56        * runtime/JSInternalPromise.cpp:
     57        (JSC::JSInternalPromise::createWithInitialValues):
     58        * runtime/JSInternalPromise.h:
     59        * runtime/JSPromise.cpp:
     60        (JSC::JSPromise::createWithInitialValues):
     61        (JSC::JSPromise::finishCreation):
     62        (JSC::JSPromise::status const):
     63        (JSC::JSPromise::result const):
     64        (JSC::JSPromise::flags const):
     65        (JSC::JSPromise::resolve):
     66        (JSC::JSPromise::reject):
     67        (JSC::JSPromise::rejectAsHandled):
     68        * runtime/JSPromise.h:
     69        (JSC::JSPromise::initialValues):
     70        (JSC::JSPromise::internalField const):
     71        (JSC::JSPromise::internalField):
     72
    1732020-04-18  Yusuke Suzuki  <ysuzuki@apple.com>
    274
  • trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h

    r260181 r260321  
    28592859    }
    28602860
    2861     case NewPromise:
    28622861    case NewGenerator:
    28632862    case NewAsyncGenerator:   
  • trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

    r260297 r260321  
    52415241                if (promiseConstructor) {
    52425242                    addToGraph(Phantom, callee);
    5243                     set(VirtualRegister(bytecode.m_dst), addToGraph(NewPromise, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())), OpInfo(bytecode.m_isInternalPromise)));
     5243                    Node* promise = addToGraph(NewInternalFieldObject, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())));
     5244                    set(VirtualRegister(bytecode.m_dst), promise);
    52445245                    alreadyEmitted = true;
    52455246                }
     
    52745275                                m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
    52755276
    5276                                 set(VirtualRegister(bytecode.m_dst), addToGraph(NewPromise, OpInfo(m_graph.registerStructure(structure)), OpInfo(bytecode.m_isInternalPromise)));
     5277                                Node* promise = addToGraph(NewInternalFieldObject, OpInfo(m_graph.registerStructure(structure)));
     5278                                set(VirtualRegister(bytecode.m_dst), promise);
    52775279                                // The callee is still live up to this point.
    52785280                                addToGraph(Phantom, callee);
     
    53095311            auto bytecode = currentInstruction->as<OpNewPromise>();
    53105312            JSGlobalObject* globalObject = m_graph.globalObjectFor(currentNodeOrigin().semantic);
    5311             set(bytecode.m_dst, addToGraph(NewPromise, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())), OpInfo(bytecode.m_isInternalPromise)));
     5313            Node* promise = addToGraph(NewInternalFieldObject, OpInfo(m_graph.registerStructure(bytecode.m_isInternalPromise ? globalObject->internalPromiseStructure() : globalObject->promiseStructure())));
     5314            set(bytecode.m_dst, promise);
    53125315            NEXT_OPCODE(op_new_promise);
    53135316        }
  • trunk/Source/JavaScriptCore/dfg/DFGClobberize.h

    r260181 r260321  
    16031603
    16041604    case NewObject:
    1605     case NewPromise:
    16061605    case NewGenerator:
    16071606    case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/dfg/DFGClobbersExitState.cpp

    r260181 r260321  
    5858    case Arrayify:
    5959    case NewObject:
    60     case NewPromise:
    6160    case NewGenerator:
    6261    case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/dfg/DFGConstantFoldingPhase.cpp

    r260181 r260321  
    832832                if (JSValue base = m_state.forNode(node->child1()).m_value) {
    833833                    if (base == (node->isInternalPromise() ? globalObject->internalPromiseConstructor() : globalObject->promiseConstructor())) {
    834                         node->convertToNewPromise(m_graph.registerStructure(node->isInternalPromise() ? globalObject->internalPromiseStructure() : globalObject->promiseStructure()));
     834                        node->convertToNewInternalFieldObject(m_graph.registerStructure(node->isInternalPromise() ? globalObject->internalPromiseStructure() : globalObject->promiseStructure()));
    835835                        changed = true;
    836836                        break;
     
    846846                                    m_graph.freeze(rareData);
    847847                                    m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
    848                                     node->convertToNewPromise(m_graph.registerStructure(structure));
     848                                    node->convertToNewInternalFieldObject(m_graph.registerStructure(structure));
    849849                                    changed = true;
    850850                                    break;
     
    872872                                        m_graph.freeze(rareData);
    873873                                        m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
    874                                         node->convertToNewInternalFieldObject(newOp, m_graph.registerStructure(structure));
     874                                        node->convertToNewInternalFieldObjectWithInlineFields(newOp, m_graph.registerStructure(structure));
    875875                                        changed = true;
    876876                                        return;
  • trunk/Source/JavaScriptCore/dfg/DFGDoesGC.cpp

    r260181 r260321  
    354354    case ArrayifyToStructure:
    355355    case NewObject:
    356     case NewPromise:
    357356    case NewGenerator:
    358357    case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp

    r260181 r260321  
    25342534        case ProfileControlFlow:
    25352535        case NewObject:
    2536         case NewPromise:
    25372536        case NewGenerator:
    25382537        case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/dfg/DFGNode.h

    r260181 r260321  
    785785    }
    786786
    787     void convertToNewPromise(RegisteredStructure structure)
     787    void convertToNewInternalFieldObject(RegisteredStructure structure)
    788788    {
    789789        ASSERT(m_op == CreatePromise);
    790         bool internal = isInternalPromise();
    791         setOpAndDefaultFlags(NewPromise);
     790        setOpAndDefaultFlags(NewInternalFieldObject);
    792791        children.reset();
    793792        m_opInfo = structure;
    794         m_opInfo2 = internal;
    795     }
    796 
    797     void convertToNewInternalFieldObject(NodeType newOp, RegisteredStructure structure)
     793        m_opInfo2 = OpInfoWrapper();
     794    }
     795
     796    void convertToNewInternalFieldObjectWithInlineFields(NodeType newOp, RegisteredStructure structure)
    798797    {
    799798        ASSERT(m_op == CreateAsyncGenerator || m_op == CreateGenerator);
     
    13131312    bool hasIsInternalPromise()
    13141313    {
    1315         return op() == CreatePromise || op() == NewPromise;
     1314        return op() == CreatePromise;
    13161315    }
    13171316
     
    19821981        case MaterializeNewInternalFieldObject:
    19831982        case NewObject:
    1984         case NewPromise:
    19851983        case NewGenerator:
    19861984        case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/dfg/DFGNodeType.h

    r260181 r260321  
    353353    /* Allocations. */\
    354354    macro(NewObject, NodeResultJS) \
    355     macro(NewPromise, NodeResultJS) \
    356355    macro(NewGenerator, NodeResultJS) \
    357356    macro(NewAsyncGenerator, NodeResultJS) \
  • trunk/Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp

    r260181 r260321  
    4343#include "JSArrayIterator.h"
    4444#include "JSCInlines.h"
     45#include "JSInternalPromise.h"
    4546#include "JSMapIterator.h"
    4647#include "JSSetIterator.h"
     
    975976                target = handleInternalFieldClass<JSSetIterator>(node, writes);
    976977                break;
     978            case JSPromiseType:
     979                if (node->structure()->classInfo() == JSInternalPromise::info())
     980                    target = handleInternalFieldClass<JSInternalPromise>(node, writes);
     981                else {
     982                    ASSERT(node->structure()->classInfo() == JSPromise::info());
     983                    target = handleInternalFieldClass<JSPromise>(node, writes);
     984                }
     985                break;
    977986            default:
    978987                DFG_CRASH(m_graph, node, "Bad structure");
  • trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp

    r260181 r260321  
    10541054
    10551055        case CreatePromise:
    1056         case NewPromise:
    10571056            setPrediction(SpecPromiseObject);
    10581057            break;
  • trunk/Source/JavaScriptCore/dfg/DFGSafeToExecute.h

    r260181 r260321  
    543543    case ConstructForwardVarargs:
    544544    case NewObject:
    545     case NewPromise:
    546545    case NewGenerator:
    547546    case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp

    r260289 r260321  
    1294912949}
    1295012950
    12951 void SpeculativeJIT::compileNewPromise(Node* node)
    12952 {
    12953     GPRTemporary result(this);
    12954     GPRTemporary scratch1(this);
    12955     GPRTemporary scratch2(this);
    12956 
    12957     GPRReg resultGPR = result.gpr();
    12958     GPRReg scratch1GPR = scratch1.gpr();
    12959     GPRReg scratch2GPR = scratch2.gpr();
    12960 
    12961     MacroAssembler::JumpList slowCases;
    12962 
    12963     FrozenValue* structure = m_graph.freezeStrong(node->structure().get());
    12964     auto butterfly = TrustedImmPtr(nullptr);
    12965     if (node->isInternalPromise())
    12966         emitAllocateJSObjectWithKnownSize<JSInternalPromise>(resultGPR, TrustedImmPtr(structure), butterfly, scratch1GPR, scratch2GPR, slowCases, sizeof(JSInternalPromise));
    12967     else
    12968         emitAllocateJSObjectWithKnownSize<JSPromise>(resultGPR, TrustedImmPtr(structure), butterfly, scratch1GPR, scratch2GPR, slowCases, sizeof(JSPromise));
    12969     m_jit.storeTrustedValue(jsNumber(static_cast<unsigned>(JSPromise::Status::Pending)), CCallHelpers::Address(resultGPR, JSInternalFieldObjectImpl<>::offsetOfInternalField(static_cast<unsigned>(JSPromise::Field::Flags))));
    12970     m_jit.storeTrustedValue(jsUndefined(), CCallHelpers::Address(resultGPR, JSInternalFieldObjectImpl<>::offsetOfInternalField(static_cast<unsigned>(JSPromise::Field::ReactionsOrResult))));
    12971     m_jit.mutatorFence(m_jit.vm());
    12972 
    12973     addSlowPathGenerator(slowPathCall(slowCases, this, node->isInternalPromise() ? operationNewInternalPromise : operationNewPromise, resultGPR, TrustedImmPtr(&vm()), TrustedImmPtr(structure)));
    12974 
    12975     cellResult(resultGPR, node);
    12976 }
    12977 
    1297812951template<typename JSClass, typename Operation>
    1297912952void SpeculativeJIT::compileNewInternalFieldObjectImpl(Node* node, Operation operation)
     
    1302512998        compileNewInternalFieldObjectImpl<JSSetIterator>(node, operationNewSetIterator);
    1302612999        break;
     13000    case JSPromiseType: {
     13001        if (node->structure()->classInfo() == JSInternalPromise::info())
     13002            compileNewInternalFieldObjectImpl<JSInternalPromise>(node, operationNewInternalPromise);
     13003        else {
     13004            ASSERT(node->structure()->classInfo() == JSPromise::info());
     13005            compileNewInternalFieldObjectImpl<JSPromise>(node, operationNewPromise);
     13006        }
     13007        break;
     13008    }
    1302713009    default:
    1302813010        DFG_CRASH(m_graph, node, "Bad structure");
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h

    r260181 r260321  
    14601460    void compileCreateAsyncGenerator(Node*);
    14611461    void compileNewObject(Node*);
    1462     void compileNewPromise(Node*);
    14631462    void compileNewGenerator(Node*);
    14641463    void compileNewAsyncGenerator(Node*);
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp

    r260181 r260321  
    32443244    case NewObject: {
    32453245        compileNewObject(node);
    3246         break;
    3247     }
    3248 
    3249     case NewPromise: {
    3250         compileNewPromise(node);
    32513246        break;
    32523247    }
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp

    r260181 r260321  
    35733573    case NewObject: {
    35743574        compileNewObject(node);
    3575         break;
    3576     }
    3577 
    3578     case NewPromise: {
    3579         compileNewPromise(node);
    35803575        break;
    35813576    }
  • trunk/Source/JavaScriptCore/dfg/DFGStoreBarrierInsertionPhase.cpp

    r260181 r260321  
    333333            switch (m_node->op()) {
    334334            case NewObject:
    335             case NewPromise:
    336335            case NewGenerator:
    337336            case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp

    r260181 r260321  
    7575    case GetButterfly:
    7676    case NewObject:
    77     case NewPromise:
    7877    case NewGenerator:
    7978    case NewAsyncGenerator:
  • trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp

    r260289 r260321  
    8585#include "JSGeneratorFunction.h"
    8686#include "JSImmutableButterfly.h"
     87#include "JSInternalPromise.h"
    8788#include "JSLexicalEnvironment.h"
    8889#include "JSMap.h"
     
    10651066        case NewObject:
    10661067            compileNewObject();
    1067             break;
    1068         case NewPromise:
    1069             compileNewPromise();
    10701068            break;
    10711069        case NewGenerator:
     
    63516349    }
    63526350
    6353     void compileNewPromise()
    6354     {
    6355         LBasicBlock slowCase = m_out.newBlock();
    6356         LBasicBlock continuation = m_out.newBlock();
    6357 
    6358         LBasicBlock lastNext = m_out.insertNewBlocksBefore(slowCase);
    6359 
    6360         LValue promise;
    6361         if (m_node->isInternalPromise())
    6362             promise = allocateObject<JSInternalPromise>(m_node->structure(), m_out.intPtrZero, slowCase);
    6363         else
    6364             promise = allocateObject<JSPromise>(m_node->structure(), m_out.intPtrZero, slowCase);
    6365         m_out.store64(m_out.constInt64(JSValue::encode(jsNumber(static_cast<unsigned>(JSPromise::Status::Pending)))), promise, m_heaps.JSInternalFieldObjectImpl_internalFields[static_cast<unsigned>(JSPromise::Field::Flags)]);
    6366         m_out.store64(m_out.constInt64(JSValue::encode(jsUndefined())), promise, m_heaps.JSInternalFieldObjectImpl_internalFields[static_cast<unsigned>(JSPromise::Field::ReactionsOrResult)]);
    6367         mutatorFence();
    6368         ValueFromBlock fastResult = m_out.anchor(promise);
    6369         m_out.jump(continuation);
    6370 
    6371         m_out.appendTo(slowCase, continuation);
    6372         ValueFromBlock slowResult = m_out.anchor(vmCall(pointerType(), m_node->isInternalPromise() ? operationNewInternalPromise : operationNewPromise, m_vmValue, frozenPointer(m_graph.freezeStrong(m_node->structure().get()))));
    6373         m_out.jump(continuation);
    6374 
    6375         m_out.appendTo(continuation, lastNext);
    6376         setJSValue(m_out.phi(pointerType(), fastResult, slowResult));
    6377     }
    6378 
    63796351    template<typename JSClass, typename Operation>
    63806352    void compileNewInternalFieldObjectImpl(Operation operation)
     
    64236395        case JSSetIteratorType:
    64246396            compileNewInternalFieldObjectImpl<JSSetIterator>(operationNewSetIterator);
     6397            break;
     6398        case JSPromiseType:
     6399            if (m_node->structure()->classInfo() == JSInternalPromise::info())
     6400                compileNewInternalFieldObjectImpl<JSInternalPromise>(operationNewInternalPromise);
     6401            else {
     6402                ASSERT(m_node->structure()->classInfo() == JSPromise::info());
     6403                compileNewInternalFieldObjectImpl<JSPromise>(operationNewPromise);
     6404            }
    64256405            break;
    64266406        default:
     
    1246912449        case JSSetIteratorType:
    1247012450            compileMaterializeNewInternalFieldObjectImpl<JSSetIterator>(operationNewSetIterator);
     12451            break;
     12452        case JSPromiseType:
     12453            if (m_node->structure()->classInfo() == JSInternalPromise::info())
     12454                compileMaterializeNewInternalFieldObjectImpl<JSInternalPromise>(operationNewInternalPromise);
     12455            else {
     12456                ASSERT(m_node->structure()->classInfo() == JSPromise::info());
     12457                compileMaterializeNewInternalFieldObjectImpl<JSPromise>(operationNewPromise);
     12458            }
    1247112459            break;
    1247212460        default:
  • trunk/Source/JavaScriptCore/ftl/FTLOperations.cpp

    r260181 r260321  
    4444#include "JSGeneratorFunction.h"
    4545#include "JSImmutableButterfly.h"
     46#include "JSInternalPromise.h"
    4647#include "JSLexicalEnvironment.h"
    4748#include "JSMapIterator.h"
     
    144145        case JSSetIteratorType:
    145146            materialize(jsCast<JSSetIterator*>(target));
     147            break;
     148        case JSPromiseType:
     149            if (target->classInfo(vm) == JSInternalPromise::info())
     150                materialize(jsCast<JSInternalPromise*>(target));
     151            else {
     152                ASSERT(target->classInfo(vm) == JSPromise::info());
     153                materialize(jsCast<JSPromise*>(target));
     154            }
    146155            break;
    147156        default:
     
    343352            JSSetIterator* result = JSSetIterator::createWithInitialValues(vm, structure);
    344353            RELEASE_ASSERT(materialization->properties().size() - 1 == JSSetIterator::numberOfInternalFields);
     354            return result;
     355        }
     356        case JSPromiseType: {
     357            if (structure->classInfo() == JSInternalPromise::info()) {
     358                JSInternalPromise* result = JSInternalPromise::createWithInitialValues(vm, structure);
     359                RELEASE_ASSERT(materialization->properties().size() - 1 == JSInternalPromise::numberOfInternalFields);
     360                return result;
     361            }
     362            ASSERT(structure->classInfo() == JSPromise::info());
     363            JSPromise* result = JSPromise::createWithInitialValues(vm, structure);
     364            RELEASE_ASSERT(materialization->properties().size() - 1 == JSPromise::numberOfInternalFields);
    345365            return result;
    346366        }
  • trunk/Source/JavaScriptCore/runtime/JSInternalPromise.cpp

    r251425 r260321  
    4141}
    4242
     43JSInternalPromise* JSInternalPromise::createWithInitialValues(VM& vm, Structure* structure)
     44{
     45    return create(vm, structure);
     46}
     47
    4348Structure* JSInternalPromise::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    4449{
  • trunk/Source/JavaScriptCore/runtime/JSInternalPromise.h

    r251691 r260321  
    4545
    4646    JS_EXPORT_PRIVATE static JSInternalPromise* create(VM&, Structure*);
     47    static JSInternalPromise* createWithInitialValues(VM&, Structure*);
    4748    static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
    4849
  • trunk/Source/JavaScriptCore/runtime/JSPromise.cpp

    r258664 r260321  
    4646}
    4747
     48JSPromise* JSPromise::createWithInitialValues(VM& vm, Structure* structure)
     49{
     50    return create(vm, structure);
     51}
     52
    4853Structure* JSPromise::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    4954{
     
    5964{
    6065    Base::finishCreation(vm);
    61     internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(static_cast<unsigned>(Status::Pending)));
    62     internalField(static_cast<unsigned>(Field::ReactionsOrResult)).set(vm, this, jsUndefined());
     66    auto values = initialValues();
     67    for (unsigned index = 0; index < values.size(); ++index)
     68        Base::internalField(index).set(vm, this, values[index]);
    6369}
    6470
     
    7278auto JSPromise::status(VM&) const -> Status
    7379{
    74     JSValue value = internalField(static_cast<unsigned>(Field::Flags)).get();
     80    JSValue value = internalField(Field::Flags).get();
    7581    uint32_t flags = value.asUInt32AsAnyInt();
    7682    return static_cast<Status>(flags & stateMask);
     
    8288    if (status == Status::Pending)
    8389        return jsUndefined();
    84     return internalField(static_cast<unsigned>(Field::ReactionsOrResult)).get();
     90    return internalField(Field::ReactionsOrResult).get();
    8591}
    8692
    8793uint32_t JSPromise::flags() const
    8894{
    89     JSValue value = internalField(static_cast<unsigned>(Field::Flags)).get();
     95    JSValue value = internalField(Field::Flags).get();
    9096    return value.asUInt32AsAnyInt();
    9197}
     
    161167    uint32_t flags = this->flags();
    162168    if (!(flags & isFirstResolvingFunctionCalledFlag)) {
    163         internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
     169        internalField(Field::Flags).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
    164170        JSGlobalObject* globalObject = this->globalObject(vm);
    165171        callFunction(lexicalGlobalObject, globalObject->resolvePromiseFunction(), this, value);
     
    175181    uint32_t flags = this->flags();
    176182    if (!(flags & isFirstResolvingFunctionCalledFlag)) {
    177         internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
     183        internalField(Field::Flags).set(vm, this, jsNumber(flags | isFirstResolvingFunctionCalledFlag));
    178184        JSGlobalObject* globalObject = this->globalObject(vm);
    179185        callFunction(lexicalGlobalObject, globalObject->rejectPromiseFunction(), this, value);
     
    189195    uint32_t flags = this->flags();
    190196    if (!(flags & isFirstResolvingFunctionCalledFlag))
    191         internalField(static_cast<unsigned>(Field::Flags)).set(vm, this, jsNumber(flags | isHandledFlag));
     197        internalField(Field::Flags).set(vm, this, jsNumber(flags | isHandledFlag));
    192198    reject(lexicalGlobalObject, value);
    193199}
  • trunk/Source/JavaScriptCore/runtime/JSPromise.h

    r258664 r260321  
    4242
    4343    JS_EXPORT_PRIVATE static JSPromise* create(VM&, Structure*);
     44    static JSPromise* createWithInitialValues(VM&, Structure*);
    4445    static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
    4546
     
    6061    };
    6162    static_assert(numberOfInternalFields == 2);
     63
     64    static std::array<JSValue, numberOfInternalFields> initialValues()
     65    {
     66        return { {
     67            jsNumber(static_cast<unsigned>(Status::Pending)),
     68            jsUndefined(),
     69        } };
     70    }
     71
     72    const WriteBarrier<Unknown>& internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); }
     73    WriteBarrier<Unknown>& internalField(Field field) { return Base::internalField(static_cast<uint32_t>(field)); }
    6274
    6375    JS_EXPORT_PRIVATE Status status(VM&) const;
Note: See TracChangeset for help on using the changeset viewer.