Skip to content
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

fix: getPrototypeOf trap get called in safari #62

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/scopeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { throwTantrum } from './utilities';
*/
const alwaysThrowHandler = new Proxy(freeze({}), {
get(target, prop) {
throwTantrum(`unexpected scope handler trap called: ${prop}`);
throwTantrum(`unexpected scope handler trap called: ${String(prop)}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Typescript language server warned me about this.

}
});

Expand All @@ -25,6 +25,8 @@ const alwaysThrowHandler = new Proxy(freeze({}), {
* - route all other property lookups at the safeGlobal.
* - hide the unsafeGlobal which lives on the scope chain above the 'with'.
* - ensure the Proxy invariants despite some global properties being frozen.
*
* @returns {ProxyHandler<any> & Record<string, any>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never did learn this comment-type language, so I can't review whether this declaration is good. Since it is in a comment, I won't block a merge here on my own ignorance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's using jsdoc-like syntax to hint ts server about the type of the function

*/
export function createScopeHandler(unsafeRec, safeGlobal, sloppyGlobals) {
const { unsafeGlobal, unsafeEval } = unsafeRec;
Expand Down Expand Up @@ -79,7 +81,6 @@ export function createScopeHandler(unsafeRec, safeGlobal, sloppyGlobals) {
return undefined;
},

// eslint-disable-next-line class-methods-use-this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. Does anyone have an automated detection of eslint-disables-*s that are not actually suppressing any warnings?

set(target, prop, value) {
// todo: allow modifications when target.hasOwnProperty(prop) and it
// is writable, assuming we've already rejected overlap (see
Expand Down Expand Up @@ -134,6 +135,13 @@ export function createScopeHandler(unsafeRec, safeGlobal, sloppyGlobals) {
}

return false;
},

// note: this is likely a bug of safari
// https://bugs.webkit.org/show_bug.cgi?id=195534

getPrototypeOf() {
return null;
}
};
}
5 changes: 3 additions & 2 deletions test/module/scopeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ test('scope handler traps', t => {

const handler = createScopeHandler({});

['has', 'get', 'set'].forEach(trap => t.doesNotThrow(() => handler[trap]));
['has', 'get', 'set', 'getPrototypeOf'].forEach(trap =>
t.doesNotThrow(() => handler[trap])
);

[
'apply',
'construct',
'defineProperty',
'delteProperty',
'getOwnProperty',
'getPrototypeOf',
'isExtensible',
'ownKeys',
'preventExtensions',
Expand Down