Chromium Code Reviews| Index: src/d8.js |
| diff --git a/src/d8.js b/src/d8.js |
| index 8d55c788e2b42fa0d591ed146316c2c29dd9f365..27a0bc39cd07107cb03fa65f0c12534aed45573a 100644 |
| --- a/src/d8.js |
| +++ b/src/d8.js |
| @@ -8,11 +8,28 @@ |
| // Used by the d8 shell to output results. |
| var stringifyDepthLimit = 4; // To avoid crashing on cyclic objects |
| +// Hacky solution to circumvent forcing --allow-natives-syntax for d8 |
|
caitp (gmail)
2015/12/22 13:21:10
Why not just compile the utility script with --all
|
| +function isProxy(o) { return false }; |
| +function JSProxyGetTarget(proxy) { }; |
| +function JSProxyGetHandler(proxy) { }; |
| + |
| +try { |
| + isProxy = Function(['object'], 'return %_IsJSProxy(object)'); |
| + JSProxyGetTarget = Function(['proxy'], |
| + 'return %JSProxyGetTarget(proxy)'); |
| + JSProxyGetHandler = Function(['proxy'], |
| + 'return %JSProxyGetHandler(proxy)'); |
| +} catch(e) {}; |
| + |
| + |
| function Stringify(x, depth) { |
| if (depth === undefined) |
| depth = stringifyDepthLimit; |
| else if (depth === 0) |
| - return "*"; |
| + return "..."; |
| + if (isProxy(x)) { |
| + return StringifyProxy(x, depth); |
| + } |
| switch (typeof x) { |
| case "undefined": |
| return "undefined"; |
| @@ -63,3 +80,12 @@ function Stringify(x, depth) { |
| return "[crazy non-standard value]"; |
| } |
| } |
| + |
| +function StringifyProxy(proxy, depth) { |
| + var proxy_type = typeof proxy; |
| + var info_object = { |
| + target: JSProxyGetTarget(proxy), |
| + handler: JSProxyGetHandler(proxy) |
| + } |
| + return '[' + proxy_type + ' Proxy ' + Stringify(info_object, depth-1) + ']'; |
| +} |