Ignore:
Timestamp:
Aug 31, 2017, 3:04:49 AM (8 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Use reifying system for "name" property of builtin JSFunction
https://bugs.webkit.org/show_bug.cgi?id=175260

Reviewed by Saam Barati.

JSTests:

  • stress/accessors-get-set-prefix.js:
  • stress/builtin-function-name.js: Added.

(shouldBe):
(shouldThrow):
(shouldBe.JSON.stringify.Object.getOwnPropertyDescriptor):
(shouldBe.JSON.stringify.Object.getOwnPropertyNames.Array.prototype.filter.sort):

  • stress/private-name-as-anonymous-builtin.js: Added.

(shouldBe):
(NotPromise):

Source/JavaScriptCore:

Currently builtin JSFunction uses direct property for "name", which is different
from usual JSFunction. Usual JSFunction uses reifying system for "name". We would like
to apply this reifying mechanism to builtin JSFunction to simplify code and drop
JSFunction::createBuiltinFunction.

We would like to store the "correct" name in FunctionExecutable. For example,
we would like to store the name like "get [Symbol.species]" to FunctionExecutable
instead of specifying name when creating JSFunction. To do so, we add a new
annotations, @getter and @overriddenName. When @getter is specified, the name of
the function becomes "get xxx". And when @overriddenName="xxx" is specified,
the name of the function becomes "xxx".

We also treat @xxx as anonymous builtin functions that cannot be achieved in
the current JS without privilege.

  • Scripts/builtins/builtins_generate_combined_header.py:

(generate_section_for_code_table_macro):

  • Scripts/builtins/builtins_generate_combined_implementation.py:

(BuiltinsCombinedImplementationGenerator.generate_secondary_header_includes):

  • Scripts/builtins/builtins_generate_separate_header.py:

(generate_section_for_code_table_macro):

  • Scripts/builtins/builtins_generate_separate_implementation.py:

(BuiltinsSeparateImplementationGenerator.generate_secondary_header_includes):

  • Scripts/builtins/builtins_model.py:

(BuiltinFunction.init):
(BuiltinFunction.fromString):

  • Scripts/builtins/builtins_templates.py:
  • Scripts/tests/builtins/JavaScriptCore-Builtin.prototype-Combined.js:

(overriddenName.string_appeared_here.match):
(intrinsic.RegExpTestIntrinsic.test):

  • Scripts/tests/builtins/JavaScriptCore-Builtin.prototype-Separate.js:

(overriddenName.string_appeared_here.match):
(intrinsic.RegExpTestIntrinsic.test):

  • Scripts/tests/builtins/expected/JavaScriptCore-Builtin.Promise-Combined.js-result:
  • Scripts/tests/builtins/expected/JavaScriptCore-Builtin.Promise-Separate.js-result:
  • Scripts/tests/builtins/expected/JavaScriptCore-Builtin.prototype-Combined.js-result:
  • Scripts/tests/builtins/expected/JavaScriptCore-Builtin.prototype-Separate.js-result:
  • Scripts/tests/builtins/expected/JavaScriptCore-BuiltinConstructor-Combined.js-result:
  • Scripts/tests/builtins/expected/JavaScriptCore-BuiltinConstructor-Separate.js-result:
  • Scripts/tests/builtins/expected/JavaScriptCore-InternalClashingNames-Combined.js-result:
  • Scripts/tests/builtins/expected/WebCore-AnotherGuardedInternalBuiltin-Separate.js-result:
  • Scripts/tests/builtins/expected/WebCore-ArbitraryConditionalGuard-Separate.js-result:
  • Scripts/tests/builtins/expected/WebCore-GuardedBuiltin-Separate.js-result:
  • Scripts/tests/builtins/expected/WebCore-GuardedInternalBuiltin-Separate.js-result:
  • Scripts/tests/builtins/expected/WebCore-UnguardedBuiltin-Separate.js-result:
  • Scripts/tests/builtins/expected/WebCore-xmlCasingTest-Separate.js-result:
  • builtins/AsyncIteratorPrototype.js:

(symbolAsyncIteratorGetter): Deleted.

  • builtins/BuiltinExecutables.cpp:

(JSC::BuiltinExecutables::BuiltinExecutables):

  • builtins/BuiltinExecutables.h:
  • builtins/BuiltinNames.h:
  • builtins/FunctionPrototype.js:

(symbolHasInstance): Deleted.

  • builtins/GlobalOperations.js:

(globalPrivate.speciesGetter): Deleted.

  • builtins/IteratorPrototype.js:

(symbolIteratorGetter): Deleted.

  • builtins/PromiseConstructor.js:

(all.newResolveElement.return.resolve):
(all.newResolveElement):
(all):

  • builtins/PromiseOperations.js:

(globalPrivate.newPromiseCapability.executor):
(globalPrivate.newPromiseCapability):
(globalPrivate.createResolvingFunctions.resolve):
(globalPrivate.createResolvingFunctions.reject):
(globalPrivate.createResolvingFunctions):

  • builtins/RegExpPrototype.js:

(match): Deleted.
(replace): Deleted.
(search): Deleted.
(split): Deleted.

  • jsc.cpp:

(functionCreateBuiltin):

  • runtime/AsyncIteratorPrototype.cpp:

(JSC::AsyncIteratorPrototype::finishCreation):

  • runtime/FunctionPrototype.cpp:

(JSC::FunctionPrototype::addFunctionProperties):

  • runtime/IteratorPrototype.cpp:

(JSC::IteratorPrototype::finishCreation):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::finishCreation):
(JSC::JSFunction::getOwnNonIndexPropertyNames):
(JSC::JSFunction::reifyLazyBoundNameIfNeeded):
(JSC::JSFunction::createBuiltinFunction): Deleted.

  • runtime/JSFunction.h:
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):

  • runtime/JSObject.cpp:

(JSC::JSObject::putDirectBuiltinFunction):
(JSC::JSObject::putDirectBuiltinFunctionWithoutTransition):

  • runtime/JSTypedArrayViewPrototype.cpp:

(JSC::JSTypedArrayViewPrototype::finishCreation):

  • runtime/Lookup.cpp:

(JSC::reifyStaticAccessor):

  • runtime/MapPrototype.cpp:

(JSC::MapPrototype::finishCreation):

  • runtime/RegExpPrototype.cpp:

(JSC::RegExpPrototype::finishCreation):

  • runtime/SetPrototype.cpp:

(JSC::SetPrototype::finishCreation):

Source/WebCore:

Test: js/dom/builtin-getter-name.html

Use @getter for JSBuiltin getters.

  • Modules/fetch/FetchResponse.js:

(bodyUsed): Deleted.
(body): Deleted.

  • Modules/streams/ReadableByteStreamController.js:

(byobRequest): Deleted.
(desiredSize): Deleted.

  • Modules/streams/ReadableStream.js:

(locked): Deleted.

  • Modules/streams/ReadableStreamBYOBReader.js:

(closed): Deleted.

  • Modules/streams/ReadableStreamBYOBRequest.js:

(view): Deleted.

  • Modules/streams/ReadableStreamDefaultController.js:

(desiredSize): Deleted.

  • Modules/streams/ReadableStreamDefaultReader.js:

(closed): Deleted.

  • Modules/streams/WritableStream.js:

(closed): Deleted.
(ready): Deleted.
(state): Deleted.

  • bindings/js/JSDOMBuiltinConstructor.h:

(WebCore::JSDOMBuiltinConstructor<JSClass>::finishCreation):

LayoutTests:

  • js/dom/builtin-getter-name-expected.txt: Added.
  • js/dom/builtin-getter-name.html: Added.
File:
1 edited

Legend:

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

    r221404 r221417  
    9292}
    9393
     94
     95void JSFunction::finishCreation(VM& vm)
     96{
     97    Base::finishCreation(vm);
     98    ASSERT(inherits(vm, info()));
     99    if (isBuiltinFunction() && jsExecutable()->name().isPrivateName()) {
     100        // This is anonymous builtin function.
     101        rareData(vm)->setHasReifiedName();
     102    }
     103}
     104
    94105void JSFunction::finishCreation(VM& vm, NativeExecutable* executable, int length, const String& name)
    95106{
     
    101112        putDirect(vm, vm.propertyNames->name, jsString(&vm, name), ReadOnly | DontEnum);
    102113    putDirect(vm, vm.propertyNames->length, jsNumber(length), ReadOnly | DontEnum);
    103 }
    104 
    105 JSFunction* JSFunction::createBuiltinFunction(VM& vm, FunctionExecutable* executable, JSGlobalObject* globalObject)
    106 {
    107     JSFunction* function = create(vm, executable, globalObject);
    108     function->putDirect(vm, vm.propertyNames->name, jsString(&vm, executable->name().string()), ReadOnly | DontEnum);
    109     return function;
    110 }
    111 
    112 JSFunction* JSFunction::createBuiltinFunction(VM& vm, FunctionExecutable* executable, JSGlobalObject* globalObject, const String& name)
    113 {
    114     JSFunction* function = create(vm, executable, globalObject);
    115     function->putDirect(vm, vm.propertyNames->name, jsString(&vm, name), ReadOnly | DontEnum);
    116     return function;
    117114}
    118115
     
    421418            if (thisObject->isBuiltinFunction() && !thisObject->hasReifiedLength())
    422419                propertyNames.add(vm.propertyNames->length);
    423             if (thisObject->inherits(vm, JSBoundFunction::info()) && !thisObject->hasReifiedName())
     420            if ((thisObject->isBuiltinFunction() || thisObject->inherits(vm, JSBoundFunction::info())) && !thisObject->hasReifiedName())
    424421                propertyNames.add(vm.propertyNames->name);
    425422        }
     
    727724        return LazyPropertyType::IsLazyProperty;
    728725
    729     if (this->inherits(vm, JSBoundFunction::info())) {
     726    if (isBuiltinFunction())
     727        reifyName(vm, exec);
     728    else if (this->inherits(vm, JSBoundFunction::info())) {
    730729        FunctionRareData* rareData = this->rareData(vm);
    731730        String name = makeString("bound ", static_cast<NativeExecutable*>(m_executable.get())->name());
Note: See TracChangeset for help on using the changeset viewer.