Changeset 202734 in webkit


Ignore:
Timestamp:
Jul 1, 2016 8:25:35 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

ES6: Implement HasRestrictedGlobalProperty when checking for global lexical tier conflicts
https://bugs.webkit.org/show_bug.cgi?id=148763

Patch by Caio Lima <Caio Lima> on 2016-07-01
Reviewed by Saam Barati

I've implemented the ES6 spec 8.1.1.4.14
(http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty)
that defines when a global property can be shadowed.

Added some test cases into global-lexical-redeclare-variable.js

  • runtime/Executable.cpp:

(JSC::ProgramExecutable::initializeGlobalProperties):

  • tests/stress/global-lexical-redeclare-variable.js:

(catch):

  • tests/stress/multiple-files-tests/global-lexical-redeclare-variable/eighth.js: Added.
  • tests/stress/multiple-files-tests/global-lexical-redeclare-variable/nineth.js: Added.
  • tests/stress/multiple-files-tests/global-lexical-redeclare-variable/seventh.js: Added.
  • tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js:
  • tests/stress/multiple-files-tests/global-lexical-redeclare-variable/tenth.js: Added.
Location:
trunk/Source/JavaScriptCore
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r202728 r202734  
     12016-07-01  Caio Lima  <ticaiolima@gmail.com>
     2
     3        ES6: Implement HasRestrictedGlobalProperty when checking for global lexical tier conflicts
     4        https://bugs.webkit.org/show_bug.cgi?id=148763
     5
     6        Reviewed by Saam Barati
     7
     8        I've implemented the ES6 spec 8.1.1.4.14
     9        (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty)
     10        that defines when a global property can be shadowed.
     11
     12        Added some test cases into global-lexical-redeclare-variable.js
     13
     14        * runtime/Executable.cpp:
     15        (JSC::ProgramExecutable::initializeGlobalProperties):
     16        * tests/stress/global-lexical-redeclare-variable.js:
     17        (catch):
     18        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/eighth.js: Added.
     19        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/nineth.js: Added.
     20        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/seventh.js: Added.
     21        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js:
     22        * tests/stress/multiple-files-tests/global-lexical-redeclare-variable/tenth.js: Added.
     23
    1242016-07-01  Youenn Fablet  <youennf@gmail.com>
    225
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r201542 r202734  
    606606        // It's an error to introduce a shadow.
    607607        for (auto& entry : lexicalDeclarations) {
    608             if (globalObject->hasProperty(exec, entry.key.get()))
    609                 return createSyntaxError(exec, makeString("Can't create duplicate variable that shadows a global property: '", String(entry.key.get()), "'"));
    610 
     608            if (globalObject->hasProperty(exec, entry.key.get())) {
     609                // The ES6 spec says that just RestrictedGlobalProperty can't be shadowed
     610                // This carried out section 8.1.1.4.14 of the ES6 spec: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty
     611                PropertyDescriptor descriptor;
     612                globalObject->getOwnPropertyDescriptor(exec, entry.key.get(), descriptor);
     613               
     614                if (descriptor.value() != jsUndefined() && !descriptor.configurable())
     615                    return createSyntaxError(exec, makeString("Can't create duplicate variable that shadows a global property: '", String(entry.key.get()), "'"));
     616            }
     617               
    611618            if (globalLexicalEnvironment->hasProperty(exec, entry.key.get())) {
    612619                if (UNLIKELY(entry.value.isConst() && !vm.globalConstRedeclarationShouldThrow() && !isStrictMode())) {
  • trunk/Source/JavaScriptCore/tests/stress/global-lexical-redeclare-variable.js

    r189279 r202734  
    6565assertExpectations();
    6666
     67// Checking if the implementation is following
     68// ES6 spec 8.1.1.4.14 http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty
     69
    6770try {
     71    sentinel = "bad";
     72    assert(Object.getOwnPropertyDescriptor(this, "globalProperty").configurable);
    6873    load("./multiple-files-tests/global-lexical-redeclare-variable/sixth.js");
     74} catch(e) {
     75    assert(false);
     76}
     77assertExpectations();
     78
     79try {
     80    sentinel = "bad";
     81    assert(Object.getOwnPropertyDescriptor(this, "Array").configurable);
     82    load("./multiple-files-tests/global-lexical-redeclare-variable/seventh.js");
     83} catch(e) {
     84    assert(false);
     85}
     86assertExpectations();
     87
     88try {
     89    sentinel = "bad";
     90    Object.defineProperty(this, 'foo', {value: 5, configurable: true, writable: true});
     91    load("./multiple-files-tests/global-lexical-redeclare-variable/eighth.js");
     92} catch(e) {
     93    assert(false);
     94}
     95assertExpectations();
     96
     97try {
     98    Object.defineProperty(this, 'bar', {value: 5, configurable: false, writable: true});
     99    load("./multiple-files-tests/global-lexical-redeclare-variable/ninth.js");
    69100} catch(e) {
    70101    assertProperError(e);
     
    73104
    74105assert(errorCount === 6);
     106
     107try {
     108    sentinel = "bad";
     109    Object.defineProperty(this, 'zoo', {value: undefined, configurable: false, writable: true});
     110    load("./multiple-files-tests/global-lexical-redeclare-variable/tenth.js");
     111} catch(e) {
     112    assert(false);
     113}
     114assertExpectations();
     115
  • trunk/Source/JavaScriptCore/tests/stress/multiple-files-tests/global-lexical-redeclare-variable/sixth.js

    r189279 r202734  
    1 let globalProperty = "bad";
    2 sentinel = "bad";
     1let globalProperty = "good";
     2sentinel = "__s__";
Note: See TracChangeset for help on using the changeset viewer.