GeezerVison is showing github.com — util,src: allow lookup of hidden values · ppaugh/node@5169311
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/util.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| | 3 | +const binding = process.binding('util'); | 3 | 4 | const prefix = `(${process.release.name}:${process.pid}) `; | 4 | 5 |
| | 6 | +exports.getHiddenValue = binding.getHiddenValue; | | 7 | + | 5 | 8 | // All the internal deprecations have to use this function only, as this will | 6 | 9 | // prepend the prefix to the actual message. | 7 | 10 | exports.deprecate = function(fn, msg) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_util.cc +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ using v8::Context; | 10 | 10 | using v8::FunctionCallbackInfo; | 11 | 11 | using v8::Local; | 12 | 12 | using v8::Object; | | 13 | +using v8::String; | 13 | 14 | using v8::Value; | 14 | 15 |
| 15 | 16 | static void IsMapIterator(const FunctionCallbackInfo<Value>& args) { | @@ -28,13 +29,31 @@ static void IsPromise(const FunctionCallbackInfo<Value>& args) { | 28 | 29 | args.GetReturnValue().Set(args[0]->IsPromise()); | 29 | 30 | } | 30 | 31 |
| | 32 | + | | 33 | +static void GetHiddenValue(const FunctionCallbackInfo<Value>& args) { | | 34 | + Environment* env = Environment::GetCurrent(args); | | 35 | + | | 36 | + if (!args[0]->IsObject()) | | 37 | + return env->ThrowTypeError("obj must be an object"); | | 38 | + | | 39 | + if (!args[1]->IsString()) | | 40 | + return env->ThrowTypeError("name must be a string"); | | 41 | + | | 42 | + Local<Object> obj = args[0].As<Object>(); | | 43 | + Local<String> name = args[1].As<String>(); | | 44 | + | | 45 | + args.GetReturnValue().Set(obj->GetHiddenValue(name)); | | 46 | +} | | 47 | + | | 48 | + | 31 | 49 | void Initialize(Local<Object> target, | 32 | 50 | Local<Value> unused, | 33 | 51 | Local<Context> context) { | 34 | 52 | Environment* env = Environment::GetCurrent(context); | 35 | 53 | env->SetMethod(target, "isMapIterator", IsMapIterator); | 36 | 54 | env->SetMethod(target, "isSetIterator", IsSetIterator); | 37 | 55 | env->SetMethod(target, "isPromise", IsPromise); | | 56 | + env->SetMethod(target, "getHiddenValue", GetHiddenValue); | 38 | 57 | } | 39 | 58 |
| 40 | 59 | } // namespace util | |
Collapse file Copy file name to clipboard +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +// Flags: --expose_internals | | 3 | + | | 4 | +const common = require('../common'); | | 5 | +const assert = require('assert'); | | 6 | +const internalUtil = require('internal/util'); | | 7 | + | | 8 | +function getHiddenValue(obj, name) { | | 9 | + return function() { | | 10 | + internalUtil.getHiddenValue(obj, name); | | 11 | + }; | | 12 | +} | | 13 | + | | 14 | +assert.throws(getHiddenValue(), /obj must be an object/); | | 15 | +assert.throws(getHiddenValue(null, 'foo'), /obj must be an object/); | | 16 | +assert.throws(getHiddenValue(undefined, 'foo'), /obj must be an object/); | | 17 | +assert.throws(getHiddenValue('bar', 'foo'), /obj must be an object/); | | 18 | +assert.throws(getHiddenValue(85, 'foo'), /obj must be an object/); | | 19 | +assert.throws(getHiddenValue({}), /name must be a string/); | | 20 | +assert.throws(getHiddenValue({}, null), /name must be a string/); | | 21 | +assert.throws(getHiddenValue({}, []), /name must be a string/); | | 22 | +assert.deepEqual(internalUtil.getHiddenValue({}, 'foo'), undefined); | | 23 | + | | 24 | +let arrowMessage; | | 25 | + | | 26 | +try { | | 27 | + require('../fixtures/syntax/bad_syntax'); | | 28 | +} catch (err) { | | 29 | + arrowMessage = internalUtil.getHiddenValue(err, 'arrowMessage'); | | 30 | +} | | 31 | + | | 32 | +assert(/bad_syntax\.js:1/.test(arrowMessage)); |
|