-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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
- Loading branch information
Showing
11 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,5 @@ JsLessThanOrEqual | |
JsCreateEnhancedFunction | ||
|
||
JsSetHostPromiseRejectionTracker | ||
|
||
JsGetProxyProperties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
|
||
let tests = [ | ||
{ | ||
name: "GetProxyProperties: no argugments", | ||
body: function () { | ||
let properties = WScript.GetProxyProperties(); | ||
assert.isUndefined(properties, "ProxyProperties of nothing should be undefined."); | ||
} | ||
}, | ||
{ | ||
name: "GetProxyProperties: non-proxy arguments", | ||
body: function () { | ||
let properties = WScript.GetProxyProperties(undefined); | ||
assert.isUndefined(properties, "ProxyProperties of undefined should be undefined."); | ||
properties = WScript.GetProxyProperties(1); | ||
assert.isUndefined(properties, "ProxyProperties of number should be undefined."); | ||
properties = WScript.GetProxyProperties({}); | ||
assert.isUndefined(properties, "ProxyProperties of non-proxy object should be undefined."); | ||
} | ||
}, | ||
{ | ||
name: "GetProxyProperties: revocable Proxy", | ||
body: function () { | ||
let revocable = Proxy.revocable({someProperty: true, otherProperty: false}, {otherProperty: true, newProperty: 5}); | ||
let proxy = revocable.proxy; | ||
let properties = WScript.GetProxyProperties(proxy); | ||
|
||
let names = Object.getOwnPropertyNames(properties); | ||
assert.areEqual(names.length, 3, "proxy properties names should have length 3."); | ||
assert.isTrue(names.includes("target")); | ||
assert.isTrue(names.includes("handler")); | ||
assert.isTrue(names.includes("revoked")); | ||
assert.isFalse(properties.revoked, "Revoked bool should be false."); | ||
|
||
names = Object.getOwnPropertyNames(properties.target); | ||
assert.areEqual(names.length, 2, "proxy properties target names should have length 2."); | ||
assert.areEqual(properties.target.someProperty, true); | ||
assert.areEqual(properties.target.otherProperty, false); | ||
|
||
names = Object.getOwnPropertyNames(properties.handler); | ||
assert.areEqual(names.length, 2, "proxy properties handler names should have length 2."); | ||
assert.areEqual(properties.handler.newProperty, 5); | ||
assert.areEqual(properties.handler.otherProperty, true); | ||
|
||
revocable.revoke(); | ||
properties = WScript.GetProxyProperties(proxy); | ||
|
||
names = Object.getOwnPropertyNames(properties); | ||
assert.areEqual(names.length, 3, "proxy properties names for revokes proxy should have length 3."); | ||
assert.isTrue(names.includes("target")); | ||
assert.isTrue(names.includes("handler")); | ||
assert.isTrue(properties.revoked, "Revoked bool should be true."); | ||
|
||
assert.isUndefined(properties.target, "Target of revoked proxy should be undefined."); | ||
assert.isUndefined(properties.handler, "Handler of revoked proxy should be undefined."); | ||
} | ||
}, | ||
{ | ||
name: "GetProxyProperties: normal Proxy", | ||
body: function () { | ||
let proxy = new Proxy({someProperty: true, otherProperty: false}, {otherProperty: true, newProperty: 5}); | ||
let properties = WScript.GetProxyProperties(proxy); | ||
|
||
let names = Object.getOwnPropertyNames(properties); | ||
assert.areEqual(names.length, 3, "proxy properties names should have length 3"); | ||
assert.isTrue(names.includes("target")); | ||
assert.isTrue(names.includes("handler")); | ||
assert.isTrue(names.includes("revoked")); | ||
assert.isFalse(properties.revoked, "Revoked bool should be false."); | ||
|
||
names = Object.getOwnPropertyNames(properties.target); | ||
assert.areEqual(names.length, 2, "proxy properties target names should have length 2"); | ||
assert.areEqual(properties.target.someProperty, true); | ||
assert.areEqual(properties.target.otherProperty, false); | ||
|
||
names = Object.getOwnPropertyNames(properties.handler); | ||
assert.areEqual(names.length, 2, "proxy properties handler names should have length 2"); | ||
assert.areEqual(properties.handler.newProperty, 5); | ||
assert.areEqual(properties.handler.otherProperty, true); | ||
} | ||
} | ||
]; | ||
|
||
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters