-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util,src: allow lookup of hidden values
This commit adds an internal util method that makes hidden values in the C++ layer visible in JS. PR-URL: #3988 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Conflicts: lib/internal/util.js
- Loading branch information
Showing
3 changed files
with
54 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
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,32 @@ | ||
'use strict'; | ||
// Flags: --expose_internals | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const internalUtil = require('internal/util'); | ||
|
||
function getHiddenValue(obj, name) { | ||
return function() { | ||
internalUtil.getHiddenValue(obj, name); | ||
}; | ||
} | ||
|
||
assert.throws(getHiddenValue(), /obj must be an object/); | ||
assert.throws(getHiddenValue(null, 'foo'), /obj must be an object/); | ||
assert.throws(getHiddenValue(undefined, 'foo'), /obj must be an object/); | ||
assert.throws(getHiddenValue('bar', 'foo'), /obj must be an object/); | ||
assert.throws(getHiddenValue(85, 'foo'), /obj must be an object/); | ||
assert.throws(getHiddenValue({}), /name must be a string/); | ||
assert.throws(getHiddenValue({}, null), /name must be a string/); | ||
assert.throws(getHiddenValue({}, []), /name must be a string/); | ||
assert.deepEqual(internalUtil.getHiddenValue({}, 'foo'), undefined); | ||
|
||
let arrowMessage; | ||
|
||
try { | ||
require('../fixtures/syntax/bad_syntax'); | ||
} catch (err) { | ||
arrowMessage = internalUtil.getHiddenValue(err, 'arrowMessage'); | ||
} | ||
|
||
assert(/bad_syntax\.js:1/.test(arrowMessage)); |