This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store strictness information during preparse.
Summary: Preparsing properly parses directives when running on functions, and stores strictness information in the functions' AST node decorations. That information was not shared with the lazy parse step, which only stored start/end locations for functions. Augment the preparsing data to also store strictness information for these functions and read it back in during the lazy parse. This also requires the semantic validator to set the strict mode based on the node strictness instead of reverifying it via scanning the prologue of the function for directives (in lazy parse mode, those bodies are empty). Reviewed By: tmikov Differential Revision: D25318752 fbshipit-source-id: 5b53f6cae31408dc034d8b0e2f30a929c95d3cc8
- Loading branch information
1 parent
4ab90f7
commit c765f74
Showing
4 changed files
with
55 additions
and
8 deletions.
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
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,24 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its 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 -non-strict -O0 %s 2>&1 | %FileCheck --match-full-lines %s | ||
// RUN: %hermes -lazy -non-strict -O0 %s 2>&1 | %FileCheck --match-full-lines %s | ||
|
||
// foo is never called, but its strictness must be set correctly. | ||
function foo(x) { | ||
"use strict"; | ||
} | ||
|
||
(function bar() { | ||
try { | ||
// .caller access is forbidden on strict functions. | ||
print(foo.caller); | ||
} catch (e) { | ||
print('caught', e.name); | ||
} | ||
})(); | ||
// CHECK: caught TypeError |