summaryrefslogtreecommitdiff
path: root/ext/kv/01_db.ts
diff options
context:
space:
mode:
authorKenta Moriuchi <moriken@kimamass.com>2024-01-04 13:12:38 +0900
committerGitHub <noreply@github.com>2024-01-04 09:42:38 +0530
commitb2cd254c35b6b1b128beea0eacdb8e814d91e003 (patch)
treed55fa5910e32d8a664aff5b680e07debea93181e /ext/kv/01_db.ts
parent48556748577ba46db5f9212d14a0fcaa90d632f6 (diff)
fix: strict type check for cross realms (#21669)
Deno v1.39 introduces `vm.runInNewContext`. This may cause problems when using `Object.prototype.isPrototypeOf` to check built-in types. ```js import vm from "node:vm"; const err = new Error(); const crossErr = vm.runInNewContext(`new Error()`); console.assert( !(crossErr instanceof Error) ); console.assert( Object.getPrototypeOf(err) !== Object.getPrototypeOf(crossErr) ); ``` This PR changes to check using internal slots solves them. --- current: ``` > import vm from "node:vm"; undefined > vm.runInNewContext(`new Error("message")`) Error {} > vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`) Date {} ``` this PR: ``` > import vm from "node:vm"; undefined > vm.runInNewContext(`new Error("message")`) Error: message at <anonymous>:1:1 > vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`) 2018-12-10T02:26:59.002Z ``` --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/kv/01_db.ts')
-rw-r--r--ext/kv/01_db.ts20
1 files changed, 10 insertions, 10 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts
index b0757a195..d607704a5 100644
--- a/ext/kv/01_db.ts
+++ b/ext/kv/01_db.ts
@@ -1,6 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-// @ts-ignore internal api
+import { core, primordials } from "ext:core/mod.js";
+import { SymbolDispose } from "ext:deno_web/00_infra.js";
+import { ReadableStream } from "ext:deno_web/06_streams.js";
const {
AsyncGeneratorPrototype,
BigIntPrototypeToString,
@@ -10,19 +12,17 @@ const {
StringPrototypeReplace,
SymbolFor,
SymbolToStringTag,
- Uint8ArrayPrototype,
+ TypedArrayPrototypeGetSymbolToStringTag,
Error,
-} = globalThis.__bootstrap.primordials;
-import { SymbolDispose } from "ext:deno_web/00_infra.js";
-import { ReadableStream } from "ext:deno_web/06_streams.js";
-const core = Deno.core;
-const ops = core.ops;
+} = primordials;
const {
op_kv_atomic_write,
op_kv_database_open,
op_kv_dequeue_next_message,
+ op_kv_encode_cursor,
op_kv_finish_dequeued_message,
op_kv_snapshot_read,
+ op_kv_watch,
op_kv_watch_next,
} = core.ensureFastOps();
@@ -30,7 +30,7 @@ const encodeCursor: (
selector: [Deno.KvKey | null, Deno.KvKey | null, Deno.KvKey | null],
boundaryKey: Deno.KvKey,
) => string = (selector, boundaryKey) =>
- ops.op_kv_encode_cursor(selector, boundaryKey);
+ op_kv_encode_cursor(selector, boundaryKey);
async function openKv(path: string) {
const rid = await op_kv_database_open(path);
@@ -319,7 +319,7 @@ class Kv {
watch(keys: Deno.KvKey[], options = {}) {
const raw = options.raw ?? false;
- const rid = ops.op_kv_watch(this.#rid, keys);
+ const rid = op_kv_watch(this.#rid, keys);
const lastEntries: (Deno.KvEntryMaybe<unknown> | undefined)[] = Array.from(
{ length: keys.length },
() => undefined,
@@ -585,7 +585,7 @@ function deserializeValue(entry: RawKvEntry): Deno.KvEntry<unknown> {
}
function serializeValue(value: unknown): RawValue {
- if (ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, value)) {
+ if (TypedArrayPrototypeGetSymbolToStringTag(value) === "Uint8Array") {
return {
kind: "bytes",
value,