From bccd2f59b037aae74ac001ff0ab2fc9889573d14 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(), v1 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/runtime/runtime-debug.cc | 4 ++++ test/parallel/test-debug-mirror-proxy.js | 30 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-debug-mirror-proxy.js diff --git a/deps/v8/include/v8-version.h b/deps/v8/include/v8-version.h index aa916fc1259186..dc783028d3a119 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 105 +#define V8_PATCH_LEVEL 106 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/deps/v8/src/runtime/runtime-debug.cc b/deps/v8/src/runtime/runtime-debug.cc index 4b98f1488b1872..544ec395e112a3 100644 --- a/deps/v8/src/runtime/runtime-debug.cc +++ b/deps/v8/src/runtime/runtime-debug.cc @@ -310,6 +310,7 @@ 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); @@ -382,6 +383,7 @@ 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); @@ -1318,6 +1320,7 @@ 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()); @@ -1408,6 +1411,7 @@ 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 new file mode 100644 index 00000000000000..71a2f389a9d1bb --- /dev/null +++ b/test/parallel/test-debug-mirror-proxy.js @@ -0,0 +1,30 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const vm = require('vm'); + +const { MakeMirror } = 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(), '#'); + +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());