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

refactor: introduce primordials for extensions/webstorage #11239

Merged
merged 1 commit into from
Jul 3, 2021
Merged
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
18 changes: 14 additions & 4 deletions extensions/webstorage/01_webstorage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

/// <reference path="../../core/internal.d.ts" />

((window) => {
const core = window.Deno.core;
const webidl = window.__bootstrap.webidl;
const {
Symbol,
ObjectDefineProperty,
ObjectFromEntries,
ObjectEntries,
ReflectGet,
Proxy,
} = window.__bootstrap.primordials;

const _persistent = Symbol("[[persistent]]");

Expand Down Expand Up @@ -96,7 +106,7 @@
},
defineProperty(target, key, descriptor) {
if (typeof key == "symbol") {
Object.defineProperty(target, key, descriptor);
ObjectDefineProperty(target, key, descriptor);
} else {
target.setItem(key, descriptor.value);
}
Expand All @@ -105,14 +115,14 @@
get(target, key) {
if (typeof key == "symbol") return target[key];
if (key in target) {
return Reflect.get(...arguments);
return ReflectGet(...arguments);
} else {
return target.getItem(key) ?? undefined;
}
},
set(target, key, value) {
if (typeof key == "symbol") {
Object.defineProperty(target, key, {
ObjectDefineProperty(target, key, {
value,
configurable: true,
});
Expand Down Expand Up @@ -151,7 +161,7 @@
return `${this.constructor.name} ${
inspect({
length: this.length,
...Object.fromEntries(Object.entries(proxy)),
...ObjectFromEntries(ObjectEntries(proxy)),
})
}`;
};
Expand Down