-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Early error on redeclaration of restricted global properties
Summary: JS has a concept of "restricted global properties" which must never be shadowed in the global scope because they are non-configurable. There are only 3 of these, so add a special check to handle restricted global properties. Reviewed By: tmikov Differential Revision: D66466325 fbshipit-source-id: faf39e42e3ba3f4660a98da3eb34fce0e8774a34
- Loading branch information
1 parent
ab480d1
commit 2897b34
Showing
6 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: (! %shermes -dump-sema %s 2>&1) | %FileCheckOrRegen %s --match-full-lines | ||
|
||
let undefined; | ||
let NaN; | ||
let Infinity; | ||
|
||
// Auto-generated content below. Please do not modify manually. | ||
|
||
// CHECK:{{.*}}restricted-global-error.js:10:5: error: Can't create duplicate variable that shadows a global property: 'undefined' | ||
// CHECK-NEXT:let undefined; | ||
// CHECK-NEXT: ^~~~~~~~~ | ||
// CHECK-NEXT:{{.*}}restricted-global-error.js:11:5: error: Can't create duplicate variable that shadows a global property: 'NaN' | ||
// CHECK-NEXT:let NaN; | ||
// CHECK-NEXT: ^~~ | ||
// CHECK-NEXT:{{.*}}restricted-global-error.js:12:5: error: Can't create duplicate variable that shadows a global property: 'Infinity' | ||
// CHECK-NEXT:let Infinity; | ||
// CHECK-NEXT: ^~~~~~~~ | ||
// CHECK-NEXT:Emitted 3 errors. exiting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %shermes -dump-sema -fno-std-globals %s | %FileCheckOrRegen %s --match-full-lines | ||
|
||
// These can be declared in block scope | ||
{ | ||
let undefined; | ||
let NaN; | ||
let Infinity; | ||
} | ||
|
||
// Auto-generated content below. Please do not modify manually. | ||
|
||
// CHECK:SemContext | ||
// CHECK-NEXT:Func loose | ||
// CHECK-NEXT: Scope %s.1 | ||
// CHECK-NEXT: Scope %s.2 | ||
// CHECK-NEXT: Decl %d.1 'undefined' Let | ||
// CHECK-NEXT: Decl %d.2 'NaN' Let | ||
// CHECK-NEXT: Decl %d.3 'Infinity' Let | ||
|
||
// CHECK:Program Scope %s.1 | ||
// CHECK-NEXT: BlockStatement Scope %s.2 | ||
// CHECK-NEXT: VariableDeclaration | ||
// CHECK-NEXT: VariableDeclarator | ||
// CHECK-NEXT: Id 'undefined' [D:E:%d.1 'undefined'] | ||
// CHECK-NEXT: VariableDeclaration | ||
// CHECK-NEXT: VariableDeclarator | ||
// CHECK-NEXT: Id 'NaN' [D:E:%d.2 'NaN'] | ||
// CHECK-NEXT: VariableDeclaration | ||
// CHECK-NEXT: VariableDeclarator | ||
// CHECK-NEXT: Id 'Infinity' [D:E:%d.3 'Infinity'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %shermes -dump-sema -fno-std-globals %s | %FileCheckOrRegen %s --match-full-lines | ||
|
||
// These can be redeclared as 'var'. | ||
var undefined; | ||
var NaN; | ||
var Infinity; | ||
|
||
// Auto-generated content below. Please do not modify manually. | ||
|
||
// CHECK:SemContext | ||
// CHECK-NEXT:Func loose | ||
// CHECK-NEXT: Scope %s.1 | ||
// CHECK-NEXT: Decl %d.1 'undefined' GlobalProperty | ||
// CHECK-NEXT: Decl %d.2 'NaN' GlobalProperty | ||
// CHECK-NEXT: Decl %d.3 'Infinity' GlobalProperty | ||
|
||
// CHECK:Program Scope %s.1 | ||
// CHECK-NEXT: VariableDeclaration | ||
// CHECK-NEXT: VariableDeclarator | ||
// CHECK-NEXT: Id 'undefined' [D:E:%d.1 'undefined'] | ||
// CHECK-NEXT: VariableDeclaration | ||
// CHECK-NEXT: VariableDeclarator | ||
// CHECK-NEXT: Id 'NaN' [D:E:%d.2 'NaN'] | ||
// CHECK-NEXT: VariableDeclaration | ||
// CHECK-NEXT: VariableDeclarator | ||
// CHECK-NEXT: Id 'Infinity' [D:E:%d.3 'Infinity'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %hermes -target=HBC %s | %FileCheck --match-full-lines %s | ||
// RUN: %shermes --exec %s | %FileCheck --match-full-lines %s | ||
|
||
{ | ||
const NaN = 1; | ||
const Infinity = 1; | ||
const undefined = 1; | ||
print([ | ||
NaN === 1 ? 'PASS NaN' : 'FAIL NaN', | ||
Infinity === 1 ? 'PASS Infinity' : 'FAIL Infinity', | ||
undefined === 1 ? 'PASS undefined' : 'FAIL undefined', | ||
].join(', ')); | ||
} | ||
// CHECK: PASS NaN, PASS Infinity, PASS undefined |