Changeset 270043 in webkit


Ignore:
Timestamp:
Nov 19, 2020 12:45:50 PM (3 years ago)
Author:
commit-queue@webkit.org
Message:

[JSC] Add support for static private class fields
https://bugs.webkit.org/show_bug.cgi?id=214297

Patch by Xan López <Xan Lopez> on 2020-11-19
Reviewed by Yusuke Suzuki.

JSTests:

Copy V8 tests for static private fields and add the test262
flag. Also add a couple more of our own tests for the sake of
completeness.

  • stress/class-fields-static-private-harmony.js: Added, with a couple additional tests.
  • stress/resources/harmony-support.js:

(assertDoesNotThrow): added.

  • test262/config.yaml:

Source/JavaScriptCore:

Static private fields come trivially now that both private and
static (public) fields are implemented.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseClass): accept static private fields if the runtime option allows it.

  • runtime/Options.cpp:

(JSC::Options::recomputeDependentOptions): usePrivateStaticClassFields depends on usePrivateClassFields.

  • runtime/OptionsList.h: add runtime option to enable static private fields.
  • tools/JSDollarVM.cpp: add a method to check for private symbols in the stress tests.

(JSC::JSC_DEFINE_HOST_FUNCTION):
(JSC::JSDollarVM::finishCreation):

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r270015 r270043  
     12020-11-19  Xan López  <xan@igalia.com>
     2
     3        [JSC] Add support for static private class fields
     4        https://bugs.webkit.org/show_bug.cgi?id=214297
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Copy V8 tests for static private fields and add the test262
     9        flag. Also add a couple more of our own tests for the sake of
     10        completeness.
     11
     12        * stress/class-fields-static-private-harmony.js: Added, with a couple additional tests.
     13        * stress/resources/harmony-support.js:
     14        (assertDoesNotThrow): added.
     15        * test262/config.yaml:
     16
    1172020-11-18  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
    218
  • trunk/JSTests/stress/class-fields-private-harmony.js

    r269965 r270043  
    362362}
    363363
    364 /*
    365 FIXME: we don't have %SymbolIsPrivate()
    366364{
    367365  let symbol = Symbol();
     
    376374  var p = new Proxy(new C, {
    377375    get: function(target, name) {
    378       if (typeof(arg) === 'symbol') {
    379         assertFalse(%SymbolIsPrivate(name));
     376      if (typeof(name) === 'symbol') {
     377        assertFalse($vm.isPrivateSymbol(name));
    380378      }
    381379      return target[name];
     
    387385  assertEquals(1, p[symbol]);
    388386}
    389 */
    390387
    391388{
  • trunk/JSTests/stress/resources/harmony-support.js

    r269922 r270043  
    195195  fail(expected, 'no exception', 'expected thrown exception');
    196196}
     197
     198/**
     199 * Runs code() and asserts that it does not throws an exception.
     200 */
     201function assertDoesNotThrow(code, name_opt) {
     202  try {
     203    if (typeof code == 'function') {
     204      code();
     205    } else {
     206      eval(code);
     207    }
     208  } catch (e) {
     209    fail("no exception", "threw an exception: " + (e.message || e));
     210  }
     211}
  • trunk/JSTests/test262/config.yaml

    r270005 r270043  
    66  class-fields-private: usePrivateClassFields
    77  class-static-fields-public: usePublicStaticClassFields
     8  class-static-fields-private: usePrivateStaticClassFields
    89  Intl.DateTimeFormat-dayPeriod: useIntlDateTimeFormatDayPeriod
    910  SharedArrayBuffer: useSharedArrayBuffer
     
    2122    - arbitrary-module-namespace-names
    2223    - class-methods-private
    23     - class-static-fields-private
    2424    - class-static-methods-private
    2525    - cleanupSome
  • trunk/Source/JavaScriptCore/ChangeLog

    r270036 r270043  
     12020-11-19  Xan López  <xan@igalia.com>
     2
     3        [JSC] Add support for static private class fields
     4        https://bugs.webkit.org/show_bug.cgi?id=214297
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Static private fields come trivially now that both private and
     9        static (public) fields are implemented.
     10
     11        * parser/Parser.cpp:
     12        (JSC::Parser<LexerType>::parseClass): accept static private fields if the runtime option allows it.
     13        * runtime/Options.cpp:
     14        (JSC::Options::recomputeDependentOptions): usePrivateStaticClassFields depends on usePrivateClassFields.
     15        * runtime/OptionsList.h: add runtime option to enable static private fields.
     16        * tools/JSDollarVM.cpp: add a method to check for private symbols in the stress tests.
     17        (JSC::JSC_DEFINE_HOST_FUNCTION):
     18        (JSC::JSDollarVM::finishCreation):
     19
    1202020-11-19  Adrian Perez de Castro  <aperez@igalia.com>
    221
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r269939 r270043  
    29722972            JSToken token = m_token;
    29732973            ident = m_token.m_data.ident;
    2974             failIfTrue(tag == ClassElementTag::Static, "Static class element cannot be private");
     2974            if (!Options::usePrivateStaticClassFields())
     2975                failIfTrue(tag == ClassElementTag::Static, "Static class element cannot be private");
    29752976            failIfTrue(isGetter || isSetter, "Cannot parse class method with private name");
    29762977            ASSERT(ident);
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r269974 r270043  
    552552        FOR_EACH_JSC_EXPERIMENTAL_OPTION(DISABLE_TIERS);
    553553    }
     554
     555    if (Options::usePrivateStaticClassFields())
     556        Options::usePrivateClassFields() = true;
    554557}
    555558
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r269939 r270043  
    526526    v(Bool, useJITCage, canUseJITCage(), Normal, nullptr) \
    527527    v(Bool, usePublicStaticClassFields, true, Normal, "If true, the parser will understand public static data fields inside classes.") \
     528    v(Bool, usePrivateStaticClassFields, false, Normal, "If true, the parser will understand private static data fields inside classes.") \
    528529
    529530enum OptionEquivalence {
  • trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp

    r268710 r270043  
    18701870static JSC_DECLARE_HOST_FUNCTION(functionIsGigacageEnabled);
    18711871static JSC_DECLARE_HOST_FUNCTION(functionToUncacheableDictionary);
     1872static JSC_DECLARE_HOST_FUNCTION(functionIsPrivateSymbol);
    18721873
    18731874const ClassInfo JSDollarVM::s_info = { "DollarVM", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDollarVM) };
     
    33783379}
    33793380
     3381JSC_DEFINE_HOST_FUNCTION(functionIsPrivateSymbol, (JSGlobalObject*, CallFrame* callFrame))
     3382{
     3383    DollarVMAssertScope assertScope;
     3384
     3385    if (!(callFrame->argument(0).isSymbol()))
     3386        return JSValue::encode(jsBoolean(false));
     3387
     3388    return JSValue::encode(jsBoolean(asSymbol(callFrame->argument(0))->uid().isPrivate()));
     3389}
     3390
    33803391constexpr unsigned jsDollarVMPropertyAttributes = PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum | PropertyAttribute::DontDelete;
    33813392
     
    35283539    addFunction(vm, "toUncacheableDictionary", functionToUncacheableDictionary, 1);
    35293540
     3541    addFunction(vm, "isPrivateSymbol", functionIsPrivateSymbol, 1);
     3542
    35303543    m_objectDoingSideEffectPutWithoutCorrectSlotStatusStructure.set(vm, this, ObjectDoingSideEffectPutWithoutCorrectSlotStatus::createStructure(vm, globalObject, jsNull()));
    35313544}
Note: See TracChangeset for help on using the changeset viewer.