mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
fix(crypto): change Crypto to interface (#10853)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
parent
368c784d7f
commit
bb0c90cadb
3 changed files with 52 additions and 47 deletions
|
@ -3,13 +3,21 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
|
const webidl = window.__bootstrap.webidl;
|
||||||
|
|
||||||
function getRandomValues(arrayBufferView) {
|
class Crypto {
|
||||||
if (!ArrayBuffer.isView(arrayBufferView)) {
|
constructor() {
|
||||||
throw new TypeError(
|
webidl.illegalConstructor();
|
||||||
"Argument 1 does not implement interface ArrayBufferView",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRandomValues(arrayBufferView) {
|
||||||
|
webidl.assertBranded(this, Crypto);
|
||||||
|
const prefix = "Failed to execute 'getRandomValues' on 'Crypto'";
|
||||||
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
||||||
|
arrayBufferView = webidl.converters.ArrayBufferView(arrayBufferView, {
|
||||||
|
prefix,
|
||||||
|
context: "Argument 1",
|
||||||
|
});
|
||||||
if (
|
if (
|
||||||
!(
|
!(
|
||||||
arrayBufferView instanceof Int8Array ||
|
arrayBufferView instanceof Int8Array ||
|
||||||
|
@ -35,16 +43,22 @@
|
||||||
return arrayBufferView;
|
return arrayBufferView;
|
||||||
}
|
}
|
||||||
|
|
||||||
function randomUUID() {
|
randomUUID() {
|
||||||
|
webidl.assertBranded(this, Crypto);
|
||||||
return core.opSync("op_crypto_random_uuid");
|
return core.opSync("op_crypto_random_uuid");
|
||||||
}
|
}
|
||||||
|
|
||||||
window.crypto = {
|
get [Symbol.toStringTag]() {
|
||||||
getRandomValues,
|
return "Crypto";
|
||||||
randomUUID,
|
}
|
||||||
};
|
|
||||||
|
[Symbol.for("Deno.customInspect")](inspect) {
|
||||||
|
return `${this.constructor.name} ${inspect({})}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.__bootstrap.crypto = {
|
window.__bootstrap.crypto = {
|
||||||
getRandomValues,
|
crypto: webidl.createBranded(Crypto),
|
||||||
randomUUID,
|
Crypto,
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
|
@ -302,7 +302,8 @@ delete Object.prototype.__proto__;
|
||||||
console: util.writable(
|
console: util.writable(
|
||||||
new Console((msg, level) => core.print(msg, level > 1)),
|
new Console((msg, level) => core.print(msg, level > 1)),
|
||||||
),
|
),
|
||||||
crypto: util.readOnly(crypto),
|
crypto: util.readOnly(crypto.crypto),
|
||||||
|
Crypto: util.nonEnumerable(crypto.Crypto),
|
||||||
fetch: util.writable(fetch.fetch),
|
fetch: util.writable(fetch.fetch),
|
||||||
performance: util.writable(performance.performance),
|
performance: util.writable(performance.performance),
|
||||||
setInterval: util.writable(timers.setInterval),
|
setInterval: util.writable(timers.setInterval),
|
||||||
|
|
|
@ -72,19 +72,9 @@
|
||||||
},
|
},
|
||||||
"historical.any.html": true,
|
"historical.any.html": true,
|
||||||
"idlharness.https.any.html": [
|
"idlharness.https.any.html": [
|
||||||
"Crypto interface: existence and properties of interface object",
|
|
||||||
"Crypto interface object length",
|
|
||||||
"Crypto interface object name",
|
|
||||||
"Crypto interface: existence and properties of interface prototype object",
|
|
||||||
"Crypto interface: existence and properties of interface prototype object's \"constructor\" property",
|
|
||||||
"Crypto interface: existence and properties of interface prototype object's @@unscopables property",
|
|
||||||
"Crypto interface: attribute subtle",
|
"Crypto interface: attribute subtle",
|
||||||
"Crypto interface: operation getRandomValues(ArrayBufferView)",
|
"Crypto interface: operation getRandomValues(ArrayBufferView)",
|
||||||
"Crypto must be primary interface of crypto",
|
|
||||||
"Stringification of crypto",
|
|
||||||
"Crypto interface: crypto must inherit property \"subtle\" with the proper type",
|
"Crypto interface: crypto must inherit property \"subtle\" with the proper type",
|
||||||
"Crypto interface: crypto must inherit property \"getRandomValues(ArrayBufferView)\" with the proper type",
|
|
||||||
"Crypto interface: calling getRandomValues(ArrayBufferView) on crypto with too few arguments must throw TypeError",
|
|
||||||
"CryptoKey interface: existence and properties of interface object",
|
"CryptoKey interface: existence and properties of interface object",
|
||||||
"CryptoKey interface object length",
|
"CryptoKey interface object length",
|
||||||
"CryptoKey interface object name",
|
"CryptoKey interface object name",
|
||||||
|
|
Loading…
Reference in a new issue