Skip to content

Commit

Permalink
refactor: migrate runtime/ and ext/canvas/ to virtual ops module (den…
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored Jan 31, 2024
1 parent 13a91a6 commit 95e4741
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions ext/canvas/01_image.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { core, internals, primordials } from "ext:core/mod.js";
const ops = core.ops;
import { internals, primordials } from "ext:core/mod.js";
import { op_image_decode_png, op_image_process } from "ext:core/ops";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
Expand Down Expand Up @@ -438,7 +438,7 @@ function createImageBitmap(
"InvalidStateError",
);
}
const { data: imageData, width, height } = ops.op_image_decode_png(data);
const { data: imageData, width, height } = op_image_decode_png(data);
const processedImage = processImage(
imageData,
width,
Expand Down Expand Up @@ -517,7 +517,7 @@ function processImage(input, width, height, sx, sy, sw, sh, options) {
* the image at the correct location, which is the inverse of the x & y of
* sourceRectangle's top-left corner.
*/
const data = ops.op_image_process(
const data = op_image_process(
new Uint8Array(TypedArrayPrototypeGetBuffer(input)),
{
width,
Expand Down
32 changes: 19 additions & 13 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ delete Intl.v8BreakIterator;

import { core, internals, primordials } from "ext:core/mod.js";
const ops = core.ops;
import {
op_bootstrap_args,
op_bootstrap_is_tty,
op_bootstrap_no_color,
op_bootstrap_pid,
op_main_module,
op_ppid,
op_set_format_exception_callback,
op_snapshot_options,
} from "ext:core/ops";
const {
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
Expand Down Expand Up @@ -331,14 +341,10 @@ function importScripts(...urls) {
}
}

function opMainModule() {
return ops.op_main_module();
}

const opArgs = memoizeLazy(() => ops.op_bootstrap_args());
const opPid = memoizeLazy(() => ops.op_bootstrap_pid());
const opPpid = memoizeLazy(() => ops.op_ppid());
setNoColorFn(() => ops.op_bootstrap_no_color() || !ops.op_bootstrap_is_tty());
const opArgs = memoizeLazy(() => op_bootstrap_args());
const opPid = memoizeLazy(() => op_bootstrap_pid());
const opPpid = memoizeLazy(() => op_ppid());
setNoColorFn(() => op_bootstrap_no_color() || !op_bootstrap_is_tty());

function formatException(error) {
if (
Expand Down Expand Up @@ -433,7 +439,7 @@ function runtimeStart(
core.setMacrotaskCallback(timers.handleTimerMacrotask);
core.setWasmStreamingCallback(fetch.handleWasmStreaming);
core.setReportExceptionCallback(event.reportException);
ops.op_set_format_exception_callback(formatException);
op_set_format_exception_callback(formatException);
version.setVersions(
denoVersion,
v8Version,
Expand Down Expand Up @@ -741,7 +747,7 @@ const {
tsVersion,
v8Version,
target,
} = ops.op_snapshot_options();
} = op_snapshot_options();

function bootstrapMainRuntime(runtimeOptions) {
if (hasBootstrapped) {
Expand Down Expand Up @@ -823,9 +829,9 @@ function bootstrapMainRuntime(runtimeOptions) {
ObjectDefineProperties(finalDenoNs, {
pid: util.getterOnly(opPid),
ppid: util.getterOnly(opPpid),
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
noColor: util.getterOnly(() => op_bootstrap_no_color()),
args: util.getterOnly(opArgs),
mainModule: util.getterOnly(opMainModule),
mainModule: util.getterOnly(() => op_main_module()),
// TODO(kt3k): Remove this export at v2
// See https://github.com/denoland/deno/issues/9294
customInspect: {
Expand Down Expand Up @@ -983,7 +989,7 @@ function bootstrapWorkerRuntime(

ObjectDefineProperties(finalDenoNs, {
pid: util.getterOnly(opPid),
noColor: util.getterOnly(() => ops.op_bootstrap_no_color()),
noColor: util.getterOnly(() => op_bootstrap_no_color()),
args: util.getterOnly(opArgs),
// TODO(kt3k): Remove this export at v2
// See https://github.com/denoland/deno/issues/9294
Expand Down

0 comments on commit 95e4741

Please sign in to comment.