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 HermesInternal.getFunctionLocation
Summary: Adds a new internal method, `HermesInternal.getFunctionLocation(f)`, which returns an object describing the source location (debug info / bytecode offset) of the function `f`. Reviewed By: jbower-fb Differential Revision: D18856943 fbshipit-source-id: d520c63274c4b537b38dfdfe13ba42c9fee2d2bb
- Loading branch information
1 parent
32c775d
commit 7364f96
Showing
5 changed files
with
253 additions
and
2 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
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,104 @@ | ||
/** | ||
* 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 -g %s \ | ||
// RUN: | %FileCheck --match-full-lines %s -check-prefix JS | ||
// RUN: %hermes -O -emit-binary -output-source-map -out %t.hbc %s && %hermes %t.hbc \ | ||
// RUN: | %FileCheck --match-full-lines %s -check-prefix BC | ||
|
||
"use strict"; | ||
|
||
function fn1() {} | ||
print(loc(fn1).fileName); | ||
// JS: {{.+}}/hermes-internal-get-function-location.js | ||
// BC: undefined | ||
print(loc(fn1).lineNumber); | ||
// JS: [[@LINE-5]] | ||
// BC: undefined | ||
print(loc(fn1).columnNumber); | ||
// JS-NEXT: 16 | ||
// BC-NEXT: undefined | ||
print(loc(fn1).cjsModuleOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: 0 | ||
print(loc(fn1).virtualOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: [[FN1OFFSET:[0-9]+]] | ||
print(loc(fn1).isNative); | ||
// JS-NEXT: false | ||
// BC-NEXT: false | ||
|
||
const fn1Bound = fn1.bind(null); | ||
print(loc(fn1Bound).fileName); | ||
// JS-NEXT: {{.+}}/hermes-internal-get-function-location.js | ||
// BC-NEXT: undefined | ||
print(loc(fn1Bound).lineNumber); | ||
// JS: [[@LINE-25]] | ||
// BC-NEXT: undefined | ||
print(loc(fn1Bound).columnNumber); | ||
// JS-NEXT: 16 | ||
// BC-NEXT: undefined | ||
print(loc(fn1Bound).cjsModuleOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: 0 | ||
print(loc(fn1Bound).virtualOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: [[FN1OFFSET]] | ||
print(loc(fn1Bound).isNative); | ||
// JS-NEXT: false | ||
// BC-NEXT: false | ||
|
||
print(loc(Object).fileName); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: undefined | ||
print(loc(Object).lineNumber); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: undefined | ||
print(loc(Object).columnNumber); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: undefined | ||
print(loc(Object).cjsModuleOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: undefined | ||
print(loc(Object).virtualOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: undefined | ||
print(loc(Object).isNative) | ||
// JS-NEXT: true | ||
// BC-NEXT: true | ||
|
||
const fn2 = eval('(x => x()) \n//# sourceURL=dummy'); | ||
print(loc(fn2).fileName); | ||
// JS-NEXT: dummy | ||
// BC-NEXT: dummy | ||
print(loc(fn2).lineNumber); | ||
// JS-NEXT: 1 | ||
// BC-NEXT: 1 | ||
print(loc(fn2).columnNumber); | ||
// JS-NEXT: 2 | ||
// BC-NEXT: 2 | ||
print(loc(fn2).cjsModuleOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: undefined | ||
print(loc(fn2).virtualOffset); | ||
// JS-NEXT: undefined | ||
// BC-NEXT: undefined | ||
print(loc(fn2).isNative); | ||
// JS-NEXT: false | ||
// BC-NEXT: false | ||
|
||
try { loc(); } catch(e) { print(e.message); } | ||
// JS-NEXT: Argument to HermesInternal.getFunctionLocation must be callable | ||
// BC-NEXT: Argument to HermesInternal.getFunctionLocation must be callable | ||
try { loc({}); } catch(e) { print(e.message); } | ||
// JS-NEXT: Argument to HermesInternal.getFunctionLocation must be callable | ||
// BC-NEXT: Argument to HermesInternal.getFunctionLocation must be callable | ||
try { loc(Math.PI); } catch(e) { print(e.message); } | ||
// JS-NEXT: Argument to HermesInternal.getFunctionLocation must be callable | ||
// BC-NEXT: Argument to HermesInternal.getFunctionLocation must be callable | ||
|
||
function loc(f) { return HermesInternal.getFunctionLocation(f); } |