forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for CommonJS caching behavior
Summary: Adds a test demonstrating that identical `require()` calls in the same basic block can return different values in the presence of circular dependencies. Reviewed By: avp Differential Revision: D25223184 fbshipit-source-id: 00c823b1f03e9f6f663ba56b089dc8624b1d0ba1
- Loading branch information
1 parent
d0e0e18
commit ac75660
Showing
3 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* 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 -O0 -commonjs %S/cjs-caching-1.js %S/cjs-caching-2.js %S/cjs-caching-3.js | %FileCheck --match-full-lines %s | ||
// RUN: %hermes -O -fstatic-require -commonjs %S/cjs-caching-1.js %S/cjs-caching-2.js %S/cjs-caching-3.js | %FileCheck --match-full-lines %s | ||
// RUN: %hermes -O -commonjs %S/cjs-caching-1.js %S/cjs-caching-2.js %S/cjs-caching-3.js | %FileCheck --match-full-lines %s | ||
|
||
const copy1 = require('./cjs-caching-2.js'); | ||
copy1.recreateExports(); | ||
const copy2 = require('./cjs-caching-2.js'); | ||
print('With no dependency cycle:'); | ||
print(copy1 === copy2 ? 'Copies are equal' : 'Copies are different'); | ||
|
||
// CHECK: With a dependency cycle: | ||
// CHECK-NEXT: Copies are different | ||
// CHECK-NEXT: With no dependency cycle: | ||
// CHECK-NEXT: Copies are equal |
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,16 @@ | ||
/** | ||
* 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: true | ||
|
||
function recreateExports() { | ||
module.exports = {recreateExports}; | ||
} | ||
|
||
recreateExports(); | ||
|
||
require('./cjs-caching-3.js'); |
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,14 @@ | ||
/** | ||
* 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: true | ||
|
||
const copy1 = require('./cjs-caching-2.js'); | ||
copy1.recreateExports(); | ||
const copy2 = require('./cjs-caching-2.js'); | ||
print('With a dependency cycle:'); | ||
print(copy1 === copy2 ? 'Copies are equal' : 'Copies are different'); |