Ignore:
Timestamp:
Nov 16, 2017, 11:08:37 AM (8 years ago)
Author:
[email protected]
Message:

It should be easier to reify lazy property names
https://bugs.webkit.org/show_bug.cgi?id=179734
<rdar://problem/35492521>

Reviewed by Keith Miller.

We reify lazy property names in a few different ways, each
specific to the JSCell implementation, in put() instead of having
a special function to do reification. Let's make that simpler.

This patch makes it easier to reify property names in a uniform
manner, and does so in JSFunction. As a follow up I'll use the
same mechanics for:

ClonedArguments callee, iteratorSymbol (Symbol.iterator)
ErrorConstructor stackTraceLimit
ErrorInstance line, column, sourceURL, stack
GenericArguments length, callee, iteratorSymbol (Symbol.iterator)
GetterSetter RELEASE_ASSERT_NOT_REACHED()
JSArray length
RegExpObject lastIndex
StringObject length

  • runtime/ClassInfo.h: Add reifyPropertyNameIfNeeded to method table.
  • runtime/JSCell.cpp:

(JSC::JSCell::reifyPropertyNameIfNeeded): by default, don't reify.

  • runtime/JSCell.h:
  • runtime/JSFunction.cpp: name and length can be reified.

(JSC::JSFunction::reifyPropertyNameIfNeeded):
(JSC::JSFunction::put):
(JSC::JSFunction::reifyLength):
(JSC::JSFunction::reifyName):
(JSC::JSFunction::reifyLazyPropertyIfNeeded):
(JSC::JSFunction::reifyLazyPropertyForHostOrBuiltinIfNeeded):
(JSC::JSFunction::reifyLazyLengthIfNeeded):
(JSC::JSFunction::reifyLazyNameIfNeeded):
(JSC::JSFunction::reifyLazyBoundNameIfNeeded):

  • runtime/JSFunction.h:

(JSC::JSFunction::isLazy):
(JSC::JSFunction::isReified):

  • runtime/JSObjectInlines.h:

(JSC::JSObject::putDirectInternal): do the reification here.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSFunction.cpp

    r222827 r224927  
    217217}
    218218
     219PropertyReificationResult JSFunction::reifyPropertyNameIfNeeded(JSCell* cell, ExecState* exec, PropertyName& propertyName)
     220{
     221    JSFunction* thisObject = jsCast<JSFunction*>(cell);
     222    PropertyStatus propertyType = thisObject->reifyLazyPropertyIfNeeded(exec->vm(), exec, propertyName);
     223    return isReified(propertyType) ? PropertyReificationResult::Something : PropertyReificationResult::Nothing;
     224}
     225
    219226CallType JSFunction::getCallData(JSCell* cell, CallData& callData)
    220227{
     
    443450
    444451    if (thisObject->isHostOrBuiltinFunction()) {
    445         LazyPropertyType propType = thisObject->reifyLazyPropertyForHostOrBuiltinIfNeeded(vm, exec, propertyName);
    446         if (propType == LazyPropertyType::IsLazyProperty)
     452        PropertyStatus propertyType = thisObject->reifyLazyPropertyForHostOrBuiltinIfNeeded(vm, exec, propertyName);
     453        if (isLazy(propertyType))
    447454            slot.disableCaching();
    448455        scope.release();
     
    476483        return typeError(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
    477484    }
    478     LazyPropertyType propType = thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName);
    479     if (propType == LazyPropertyType::IsLazyProperty)
     485    PropertyStatus propertyType = thisObject->reifyLazyPropertyIfNeeded(vm, exec, propertyName);
     486    if (isLazy(propertyType))
    480487        slot.disableCaching();
    481488    scope.release();
     
    643650    unsigned initialAttributes = PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly;
    644651    const Identifier& identifier = vm.propertyNames->length;
     652    rareData->setHasReifiedLength();
    645653    putDirect(vm, identifier, initialValue, initialAttributes);
    646 
    647     rareData->setHasReifiedLength();
    648654}
    649655
     
    684690        name = makeString("set ", name);
    685691
     692    rareData->setHasReifiedName();
    686693    putDirect(vm, propID, jsString(exec, name), initialAttributes);
    687     rareData->setHasReifiedName();
    688 }
    689 
    690 JSFunction::LazyPropertyType JSFunction::reifyLazyPropertyIfNeeded(VM& vm, ExecState* exec, PropertyName propertyName)
    691 {
    692     if (reifyLazyLengthIfNeeded(vm, exec, propertyName) == LazyPropertyType::IsLazyProperty)
    693         return LazyPropertyType::IsLazyProperty;
    694     if (propertyName == vm.propertyNames->name) {
    695         if (!hasReifiedName())
    696             reifyName(vm, exec);
    697         return LazyPropertyType::IsLazyProperty;
    698     }
    699     return LazyPropertyType::NotLazyProperty;
    700 }
    701 
    702 JSFunction::LazyPropertyType JSFunction::reifyLazyPropertyForHostOrBuiltinIfNeeded(VM& vm, ExecState* exec, PropertyName propertyName)
     694}
     695
     696JSFunction::PropertyStatus JSFunction::reifyLazyPropertyIfNeeded(VM& vm, ExecState* exec, PropertyName propertyName)
     697{
     698    if (isHostOrBuiltinFunction())
     699        return PropertyStatus::Eager;
     700    PropertyStatus lazyLength = reifyLazyLengthIfNeeded(vm, exec, propertyName);
     701    if (isLazy(lazyLength))
     702        return lazyLength;
     703    PropertyStatus lazyName = reifyLazyNameIfNeeded(vm, exec, propertyName);
     704    if (isLazy(lazyName))
     705        return lazyName;
     706    return PropertyStatus::Eager;
     707}
     708
     709JSFunction::PropertyStatus JSFunction::reifyLazyPropertyForHostOrBuiltinIfNeeded(VM& vm, ExecState* exec, PropertyName propertyName)
    703710{
    704711    ASSERT(isHostOrBuiltinFunction());
    705712    if (isBuiltinFunction()) {
    706         if (reifyLazyLengthIfNeeded(vm, exec, propertyName) == LazyPropertyType::IsLazyProperty)
    707             return LazyPropertyType::IsLazyProperty;
     713        PropertyStatus lazyLength = reifyLazyLengthIfNeeded(vm, exec, propertyName);
     714        if (isLazy(lazyLength))
     715            return lazyLength;
    708716    }
    709717    return reifyLazyBoundNameIfNeeded(vm, exec, propertyName);
    710718}
    711719
    712 JSFunction::LazyPropertyType JSFunction::reifyLazyLengthIfNeeded(VM& vm, ExecState*, PropertyName propertyName)
     720JSFunction::PropertyStatus JSFunction::reifyLazyLengthIfNeeded(VM& vm, ExecState*, PropertyName propertyName)
    713721{
    714722    if (propertyName == vm.propertyNames->length) {
    715         if (!hasReifiedLength())
     723        if (!hasReifiedLength()) {
    716724            reifyLength(vm);
    717         return LazyPropertyType::IsLazyProperty;
    718     }
    719     return LazyPropertyType::NotLazyProperty;
    720 }
    721 
    722 JSFunction::LazyPropertyType JSFunction::reifyLazyBoundNameIfNeeded(VM& vm, ExecState* exec, PropertyName propertyName)
     725            return PropertyStatus::Reified;
     726        }
     727        return PropertyStatus::Lazy;
     728    }
     729    return PropertyStatus::Eager;
     730}
     731
     732JSFunction::PropertyStatus JSFunction::reifyLazyNameIfNeeded(VM& vm, ExecState* exec, PropertyName propertyName)
     733{
     734    if (propertyName == vm.propertyNames->name) {
     735        if (!hasReifiedName()) {
     736            reifyName(vm, exec);
     737            return PropertyStatus::Reified;
     738        }
     739        return PropertyStatus::Lazy;
     740    }
     741    return PropertyStatus::Eager;
     742}
     743
     744JSFunction::PropertyStatus JSFunction::reifyLazyBoundNameIfNeeded(VM& vm, ExecState* exec, PropertyName propertyName)
    723745{
    724746    const Identifier& nameIdent = vm.propertyNames->name;
    725747    if (propertyName != nameIdent)
    726         return LazyPropertyType::NotLazyProperty;
     748        return PropertyStatus::Eager;
    727749
    728750    if (hasReifiedName())
    729         return LazyPropertyType::IsLazyProperty;
     751        return PropertyStatus::Lazy;
    730752
    731753    if (isBuiltinFunction())
     
    735757        String name = makeString("bound ", static_cast<NativeExecutable*>(m_executable.get())->name());
    736758        unsigned initialAttributes = PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly;
     759        rareData->setHasReifiedName();
    737760        putDirect(vm, nameIdent, jsString(exec, name), initialAttributes);
    738         rareData->setHasReifiedName();
    739     }
    740     return LazyPropertyType::IsLazyProperty;
     761    }
     762    return PropertyStatus::Reified;
    741763}
    742764
Note: See TracChangeset for help on using the changeset viewer.