mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
refactor: use primordials for extensions/webstorage (#11239)
This commit is contained in:
parent
caf87694d0
commit
e90b97ada2
1 changed files with 14 additions and 4 deletions
|
@ -1,8 +1,18 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
/// <reference path="../../core/internal.d.ts" />
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const webidl = window.__bootstrap.webidl;
|
const webidl = window.__bootstrap.webidl;
|
||||||
|
const {
|
||||||
|
Symbol,
|
||||||
|
ObjectDefineProperty,
|
||||||
|
ObjectFromEntries,
|
||||||
|
ObjectEntries,
|
||||||
|
ReflectGet,
|
||||||
|
Proxy,
|
||||||
|
} = window.__bootstrap.primordials;
|
||||||
|
|
||||||
const _persistent = Symbol("[[persistent]]");
|
const _persistent = Symbol("[[persistent]]");
|
||||||
|
|
||||||
|
@ -96,7 +106,7 @@
|
||||||
},
|
},
|
||||||
defineProperty(target, key, descriptor) {
|
defineProperty(target, key, descriptor) {
|
||||||
if (typeof key == "symbol") {
|
if (typeof key == "symbol") {
|
||||||
Object.defineProperty(target, key, descriptor);
|
ObjectDefineProperty(target, key, descriptor);
|
||||||
} else {
|
} else {
|
||||||
target.setItem(key, descriptor.value);
|
target.setItem(key, descriptor.value);
|
||||||
}
|
}
|
||||||
|
@ -105,14 +115,14 @@
|
||||||
get(target, key) {
|
get(target, key) {
|
||||||
if (typeof key == "symbol") return target[key];
|
if (typeof key == "symbol") return target[key];
|
||||||
if (key in target) {
|
if (key in target) {
|
||||||
return Reflect.get(...arguments);
|
return ReflectGet(...arguments);
|
||||||
} else {
|
} else {
|
||||||
return target.getItem(key) ?? undefined;
|
return target.getItem(key) ?? undefined;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set(target, key, value) {
|
set(target, key, value) {
|
||||||
if (typeof key == "symbol") {
|
if (typeof key == "symbol") {
|
||||||
Object.defineProperty(target, key, {
|
ObjectDefineProperty(target, key, {
|
||||||
value,
|
value,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
@ -151,7 +161,7 @@
|
||||||
return `${this.constructor.name} ${
|
return `${this.constructor.name} ${
|
||||||
inspect({
|
inspect({
|
||||||
length: this.length,
|
length: this.length,
|
||||||
...Object.fromEntries(Object.entries(proxy)),
|
...ObjectFromEntries(ObjectEntries(proxy)),
|
||||||
})
|
})
|
||||||
}`;
|
}`;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue