summaryrefslogtreecommitdiff
path: root/ext/webgpu
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/webgpu
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/webgpu')
-rw-r--r--ext/webgpu/01_webgpu.js59
1 files changed, 24 insertions, 35 deletions
diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js
index 3e8978fef..c8258621f 100644
--- a/ext/webgpu/01_webgpu.js
+++ b/ext/webgpu/01_webgpu.js
@@ -10,11 +10,10 @@ import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { EventTarget } from "ext:deno_web/02_event.js";
-import DOMException from "ext:deno_web/01_dom_exception.js";
+import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const {
ArrayBuffer,
- ArrayBufferIsView,
ArrayIsArray,
ArrayPrototypeFilter,
ArrayPrototypeMap,
@@ -45,10 +44,13 @@ const {
SymbolIterator,
TypeError,
Uint32Array,
- Uint32ArrayPrototype,
Uint8Array,
} = primordials;
const {
+ isDataView,
+ isTypedArray,
+} = core;
+const {
op_webgpu_buffer_get_map_async,
op_webgpu_request_adapter,
op_webgpu_request_adapter_info,
@@ -1690,17 +1692,14 @@ class GPUQueue {
});
/** @type {ArrayBufferLike} */
let abLike = data;
- if (ArrayBufferIsView(data)) {
- if (TypedArrayPrototypeGetSymbolToStringTag(data) !== undefined) {
- // TypedArray
- abLike = TypedArrayPrototypeGetBuffer(
- /** @type {Uint8Array} */ (data),
- );
- } else {
- // DataView
- abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data));
- }
+ if (isTypedArray(data)) {
+ abLike = TypedArrayPrototypeGetBuffer(
+ /** @type {Uint8Array} */ (data),
+ );
+ } else if (isDataView(data)) {
+ abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data));
}
+
const { err } = ops.op_webgpu_write_buffer(
device.rid,
bufferRid,
@@ -1744,16 +1743,12 @@ class GPUQueue {
/** @type {ArrayBufferLike} */
let abLike = data;
- if (ArrayBufferIsView(data)) {
- if (TypedArrayPrototypeGetSymbolToStringTag(data) !== undefined) {
- // TypedArray
- abLike = TypedArrayPrototypeGetBuffer(
- /** @type {Uint8Array} */ (data),
- );
- } else {
- // DataView
- abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data));
- }
+ if (isTypedArray(data)) {
+ abLike = TypedArrayPrototypeGetBuffer(
+ /** @type {Uint8Array} */ (data),
+ );
+ } else if (isDataView(data)) {
+ abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data));
}
const { err } = ops.op_webgpu_write_texture(
@@ -3778,10 +3773,8 @@ class GPURenderPassEncoder {
selfContext: "this",
});
if (
- !(ObjectPrototypeIsPrototypeOf(
- Uint32ArrayPrototype,
- dynamicOffsetsData,
- ))
+ TypedArrayPrototypeGetSymbolToStringTag(dynamicOffsetsData) !==
+ "Uint32Array"
) {
dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []);
dynamicOffsetsDataStart = 0;
@@ -4337,10 +4330,8 @@ class GPUComputePassEncoder {
selfContext: "this",
});
if (
- !(ObjectPrototypeIsPrototypeOf(
- Uint32ArrayPrototype,
- dynamicOffsetsData,
- ))
+ TypedArrayPrototypeGetSymbolToStringTag(dynamicOffsetsData) !==
+ "Uint32Array"
) {
dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []);
dynamicOffsetsDataStart = 0;
@@ -4555,10 +4546,8 @@ class GPURenderBundleEncoder {
selfContext: "this",
});
if (
- !(ObjectPrototypeIsPrototypeOf(
- Uint32ArrayPrototype,
- dynamicOffsetsData,
- ))
+ TypedArrayPrototypeGetSymbolToStringTag(dynamicOffsetsData) !==
+ "Uint32Array"
) {
dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []);
dynamicOffsetsDataStart = 0;