-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSRT APIs for Proxy #950
Comments
Added APIs `GetTarget()`, `GetHandler()` for Proxy. Today, there is no way to extract these fields through JSRT APIs, these APIs return `undefined` for now. I have opened chakra-core/ChakraCore#950 to track this. Likewise, as per ES6 spec, there is no way to detect if an object is a Proxy hence `IsProxy()` too needs an equivalent JSRT API.
Added APIs `GetTarget()`, `GetHandler()` for Proxy. Today, there is no way to extract these fields through JSRT APIs, these APIs return `undefined` for now. I have opened chakra-core/ChakraCore#950 to track this. Likewise, as per ES6 spec, there is no way to detect if an object is a Proxy hence `IsProxy()` too needs an equivalent JSRT API.
Added APIs `GetTarget()`, `GetHandler()` for Proxy. Today, there is no way to extract these fields through JSRT APIs, these APIs return `undefined` for now. I have opened chakra-core/ChakraCore#950 to track this. Likewise, as per ES6 spec, there is no way to detect if an object is a Proxy hence `IsProxy()` too needs an equivalent JSRT API.
Added APIs `GetTarget()`, `GetHandler()` for Proxy. Today, there is no way to extract these fields through JSRT APIs, these APIs return `undefined` for now. I have opened chakra-core/ChakraCore#950 to track this. Likewise, as per ES6 spec, there is no way to detect if an object is a Proxy hence `IsProxy()` too needs an equivalent JSRT API. PR-URL: nodejs#69 Reviewed-By: Jianchun Xu <Jianchun.Xu@microsoft.com>
@digitalinfinity is this still needed? |
Yes, the v8 Proxy implementation in chakrashim is still just a stub |
Do you want a PR for these? Looks easy enough. My only questions would be: |
Maybe something like this: JsGetProxyProperties(_In_ JsValueRef proxyObject,
_Out_ bool* isProxy,
_Out_opt_ JsValueRef* Target,
_Out_opt_ JsValueRef* Handler); |
Sure! Let's hash out what's needed first and how we will test it. I'd imagine a NativeTests addition for this would be part of it. |
Options for the API:
JsGetProxyProperties(_In_ JsValueRef proxyObject,
_Out_ bool* isProxy,
_Out_opt_ JsValueRef* Target,
_Out_opt_ JsValueRef* Handler); Call it with a normal Proxy would output: Call it with a revoked Proxy, would output: Call it with something that is not a proxy and you'd be given:
Options for testing:
Thoughts? |
I like the elegance of one function. Let's explore that first. I think it's probably fairly likely if they want to know Target they will also want to know Handler, and need to guard accessing those on whether the object is a proxy at all. There's value in keeping the APIs lean and this will be an experimental API at first so we could provide fewer APIs at first and go from there if there are perf concerns. If getting all the information has significantly more overhead and "all the info" is not the most common scenario in practice, then we can explore splitting up the API. I can imagine this pattern being pretty common:
@digitalinfinity what do you think? Also would you like this change targeted at |
@rhuanjl Any updates on this? If you don't plan on writing this, thats fine, but Node's new |
And, for that reason, I vote that any such change go into release/1.9 unless we plan on making 1.10 very soon. |
@jackhorton I was waiting on further comment before writing anything as the ask didn't seem quite fixed yet. I'll have time to write the code this weekend if we can be sure what's wanted before then. |
I agree with @dilijev about the design strategy. I don't think there will be a perf impact to get the target and handler, but also we could perhaps pass null for those if we don't want that information and are concerned about doing extra work. |
…fixes #950 Merge pull request #4806 from rhuanjl:JsGetProxyProperties Responding to issue #950 This PR: 1. Adds a JavascriptProxy::IsRevoked method to the Javascript proxy class (necessary for the below) 2. Adds a JsGetProxyProperties API to Jsrt which can: a) check if an object is a proxy -> set a provided bool to true/false b) if it is a proxy check if it's revoked c) if it is a revoked proxy set provided target and handler references to nullptr d) if it is a proxy that is not revoked provide references to it's target and handler 3. Tracks the same API through to WScriptJsrt in ch 4. Adds a test that uses the ch implementation (Targeting 1.9 as this will assist with an issue in node-chakracore nodejs/node-chakracore#488 ) **CC:** @jackhorton @kfarnung @dilijev
Just a heads up chakra-node has shipped v10 so now beyond |
Currently
target
andhandler
as internal fields ofJavascriptProxy.cpp
and there is no way to retrieve them natively. Recently node started taking dependency on these fields natively. This breaks node on chakracore as chakracore doesn't have these fields exposed via JSRT. Additionally as per ES6 spec, there is no way to check if an object is a proxy or not.This issue is to track adding below JSRT APIs
GetTargetOfProxy
GetHandlerOfProxy
IsProxy
The text was updated successfully, but these errors were encountered: