From 9e2d85e4419131c1e3265afe83f1823a5fb0749c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 24 Jul 2017 17:05:30 +0200 Subject: [PATCH] v8: handle proxy objects in MakeMirror(), v2 PR-URL: https://github.com/nodejs/node/pull/14343 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- deps/v8/include/v8-version.h | 2 +- deps/v8/src/debug/debug.js | 1 + deps/v8/src/debug/mirrors.js | 36 ++++++++++++++++++++++++ deps/v8/src/runtime/runtime-debug.cc | 4 --- test/parallel/test-debug-mirror-proxy.js | 29 ++++++------------- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index dc783028d3a119..955fcd5646cef5 100644 --- a/deps/v8/include/v8-version.h +++ b/deps/v8/include/v8-version.h @@ -11,7 +11,7 @@ #define V8_MAJOR_VERSION 5 #define V8_MINOR_VERSION 1 #define V8_BUILD_NUMBER 281 -#define V8_PATCH_LEVEL 106 +#define V8_PATCH_LEVEL 107 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/deps/v8/src/debug/debug.js b/deps/v8/src/debug/debug.js index 6849bf534506b7..7029da11175eee 100644 --- a/deps/v8/src/debug/debug.js +++ b/deps/v8/src/debug/debug.js @@ -864,6 +864,7 @@ Debug.debuggerFlags = function() { }; Debug.MakeMirror = MakeMirror; +Debug.MakeMirrorSerializer = MakeMirrorSerializer; function MakeExecutionState(break_id) { return new ExecutionState(break_id); diff --git a/deps/v8/src/debug/mirrors.js b/deps/v8/src/debug/mirrors.js index 0696ec988e4125..dbe8c384cc8cd1 100644 --- a/deps/v8/src/debug/mirrors.js +++ b/deps/v8/src/debug/mirrors.js @@ -60,6 +60,7 @@ utils.Import(function(from) { // - FrameMirror // - ScriptMirror // - ScopeMirror +// - ProxyMirror // Type names of the different mirrors. var MirrorType = { @@ -84,6 +85,7 @@ var MirrorType = { SET_TYPE : 'set', ITERATOR_TYPE : 'iterator', GENERATOR_TYPE : 'generator', + PROXY_TYPE : 'proxy', } @@ -157,6 +159,8 @@ function MakeMirror(value, opt_transient) { mirror = new StringMirror(value); } else if (IS_SYMBOL(value)) { mirror = new SymbolMirror(value); + } else if (IS_PROXY(value)) { + mirror = new ProxyMirror(value); } else if (IS_ARRAY(value)) { mirror = new ArrayMirror(value); } else if (IS_DATE(value)) { @@ -342,6 +346,15 @@ Mirror.prototype.isSymbol = function() { }; +/** + * Check whether the mirror reflects a proxy object. + * @returns {boolean} True if the mirror reflects a proxy object. + */ +Mirror.prototype.isProxy = function() { + return this instanceof ProxyMirror; +}; + + /** * Check whether the mirror reflects an object. * @returns {boolean} True if the mirror reflects an object @@ -2439,6 +2452,29 @@ ContextMirror.prototype.data = function() { }; +/** + * Mirror object for proxies. + * @param {value} value The value reflected by this mirror. + * @constructor + * @extends Mirror + */ +function ProxyMirror(value) { + %_Call(Mirror, this, MirrorType.PROXY_TYPE); + this.value_ = value; +} +inherits(ProxyMirror, Mirror); + + +ProxyMirror.prototype.value = function() { + return this.value_; +}; + + +ProxyMirror.prototype.toText = function() { + return '#'; +}; + + /** * Returns a mirror serializer * diff --git a/deps/v8/src/runtime/runtime-debug.cc b/deps/v8/src/runtime/runtime-debug.cc index 544ec395e112a3..4b98f1488b1872 100644 --- a/deps/v8/src/runtime/runtime-debug.cc +++ b/deps/v8/src/runtime/runtime-debug.cc @@ -310,7 +310,6 @@ RUNTIME_FUNCTION(Runtime_DebugGetPropertyDetails) { DCHECK(args.length() == 2); - if (args[0]->IsJSProxy()) return isolate->heap()->undefined_value(); CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); @@ -383,7 +382,6 @@ RUNTIME_FUNCTION(Runtime_DebugGetProperty) { DCHECK(args.length() == 2); - if (args[0]->IsJSProxy()) return isolate->heap()->undefined_value(); CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); @@ -1320,7 +1318,6 @@ static bool HasInPrototypeChainIgnoringProxies(Isolate* isolate, RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { HandleScope scope(isolate); DCHECK(args.length() == 3); - if (!args[0]->IsJSObject()) return *isolate->factory()->NewJSArray(0); CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); CONVERT_ARG_HANDLE_CHECKED(Object, filter, 1); RUNTIME_ASSERT(filter->IsUndefined() || filter->IsJSObject()); @@ -1411,7 +1408,6 @@ RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { RUNTIME_FUNCTION(Runtime_DebugGetPrototype) { HandleScope shs(isolate); DCHECK(args.length() == 1); - if (args[0]->IsJSProxy()) return isolate->heap()->undefined_value(); CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); Handle prototype; // TODO(1543): Come up with a solution for clients to handle potential errors diff --git a/test/parallel/test-debug-mirror-proxy.js b/test/parallel/test-debug-mirror-proxy.js index 71a2f389a9d1bb..458d8e4ecd0f15 100644 --- a/test/parallel/test-debug-mirror-proxy.js +++ b/test/parallel/test-debug-mirror-proxy.js @@ -4,27 +4,16 @@ require('../common'); const assert = require('assert'); const vm = require('vm'); -const { MakeMirror } = vm.runInDebugContext('Debug'); +const { MakeMirror, MakeMirrorSerializer } = vm.runInDebugContext('Debug'); const proxy = new Proxy({ x: 1, y: 2 }, { get: Reflect.get }); const mirror = MakeMirror(proxy, /* transient */ true); -assert.strictEqual(mirror.protoObject().value(), undefined); -assert.strictEqual(mirror.className(), 'Object'); -assert.strictEqual(mirror.constructorFunction().value(), undefined); -assert.strictEqual(mirror.prototypeObject().value(), undefined); -assert.strictEqual(mirror.hasNamedInterceptor(), false); -assert.strictEqual(mirror.hasIndexedInterceptor(), false); -assert.strictEqual(mirror.referencedBy(1).length, 0); -assert.strictEqual(mirror.toText(), '#'); +assert.strictEqual(mirror.isProxy(), true); +assert.strictEqual(mirror.toText(), '#'); +assert.strictEqual(mirror.value(), proxy); -const propertyNames = mirror.propertyNames(); -const DebugContextArray = propertyNames.constructor; -assert.deepStrictEqual(propertyNames, DebugContextArray.from(['x', 'y'])); - -const properties = mirror.properties(); -assert.strictEqual(properties.length, 2); -// UndefinedMirror because V8 cannot retrieve the values without invoking -// the handler. Could be turned a PropertyMirror but mirror.value() would -// still be an UndefinedMirror. This seems Good Enough for now. -assert(properties[0].isUndefined()); -assert(properties[1].isUndefined()); +const serializer = MakeMirrorSerializer(/* details */ true); +const serialized = serializer.serializeValue(mirror); +assert.deepStrictEqual(Object.keys(serialized).sort(), ['text', 'type']); +assert.strictEqual(serialized.type, 'proxy'); +assert.strictEqual(serialized.text, '#');