Comments (11)
Regarding the JSON.stringify, a workaround is to do this:
var proxy = new Proxy(obj, {
get: function(target, property, receiver) {
if (property === 'toJSON') {
return () => target;
}
});
from harmony-reflect.
I just checked these issues against the most recent version of v8 (3.17.16.2). Issue 1 from above (JSON.stringify dying on proxies) is fixed. Issue 3 from above (Arrays returning "object Object") is still there, as the following d8 console session shows:
V8 version 3.17.16.2 [console: readline]
d8> load("/home/parallels/git/experiments/node_modules/harmony-reflect/reflect.js");
undefined
d8> a = ["a","b","c"];
["a", "b", "c"]
d8> Object.prototype.toString.apply(a);
"[object Array]"
d8> var p = Proxy(a, {});
undefined
d8> print(p);
a,b,c
undefined
d8> print(a);
a,b,c
undefined
d8> Object.prototype.toString.apply(p);
"[object Object]"
from harmony-reflect.
Thanks for clarifying. I'd meant to report these results using that same Node version but had invoked the wrong one. Whoops.
I see the same thing as @billmark, which is nice because the JSON.stringify issue I complained about as (1) above actually is fixed, but now that it works, it turns out that it, just like JSON2.stringify and util.inspect, does not think that proxy-to-array is an array.
So scratch complaint (1), but (2) and (3) turn out to be even truer than I thought.
from harmony-reflect.
More details: I also checked against the slightly more recent "bleeding_edge" version of v8, "3.18.0 (candidate)", and it still has the issue that calling Object.prototype.toString on a proxied array returns "[object Object]" rather than "[object Array]".
from harmony-reflect.
I just committed a patch so that Array.isArray
and Object.prototype.toString
automatically unwrap proxies. Those methods now return the expected result on proxies for arrays:
var p = Proxy([] , {});
Object.prototype.toString.call(p) // [object Array]
Array.isArray(p) // true
However, JSON.stringify
still serializes proxies-for-arrays as objects. This is because that algorithm internally uses its own isArray check, which my library cannot intercept. AFAICT, this is something that can be solved only by proxies directly provided by the engine. The alternative is to re-implement JSON.stringify in JavaScript itself, which doesn't seem to be a good alternative.
from harmony-reflect.
Thanks, Tom.
from harmony-reflect.
Has any of this made it's way to the npm module?
from harmony-reflect.
Not yet. Thanks for bringing it to my attention. I'll upload a new npm package shortly.
from harmony-reflect.
npm module v0.0.5 now contains the patches to Array.isArray
and Object.prototype.toString
to unwrap proxies.
from harmony-reflect.
Thanks, Tom!
from harmony-reflect.
Thanks!
from harmony-reflect.
Related Issues (20)
- "proxies not supported on this platform" error when multiple packages require harmony-reflect HOT 9
- get handler with Symbol HOT 6
- Reflect.Loader HOT 2
- Incompatible with Edge browser HOT 4
- Extending proxy classes HOT 3
- Cannot properly Proxy 'os' methods HOT 2
- Possible incompatibility gulp/jscs HOT 1
- Provide option to turn off warning "getOwnPropertyNames trap is deprecated. Use ownKeys instead" HOT 6
- harmony-reflect borks node repl
- Error when using Reflect.construct on ES2015 classes
- Calling Object.getOwnPropertySymbols() on a Proxy throws an error HOT 2
- 'Illegal access' error when using Object.assign() HOT 1
- Is there a way to conditionally load harmony-reflect HOT 2
- Question: Does this work with IE11? HOT 2
- Conflict with `reflect-metadata` HOT 6
- What is the actual license of this package? HOT 2
- Reflect.construct incorrectly calls newTarget, causing infinite loops HOT 1
- Is Reflect.set working as intended?
- Index not found HOT 8
- Does this polyfill works for chrome version 38 ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from harmony-reflect.