summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/v8.ts13
-rw-r--r--tests/unit_node/v8_test.ts11
2 files changed, 20 insertions, 4 deletions
diff --git a/ext/node/polyfills/v8.ts b/ext/node/polyfills/v8.ts
index a1ea16430..cad00bd7f 100644
--- a/ext/node/polyfills/v8.ts
+++ b/ext/node/polyfills/v8.ts
@@ -1,14 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+/// <reference path="../../core/internal.d.ts" />
+
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
+import { core } from "ext:core/mod.js";
import {
op_v8_cached_data_version_tag,
op_v8_get_heap_statistics,
} from "ext:core/ops";
+import { Buffer } from "node:buffer";
+
import { notImplemented } from "ext:deno_node/_utils.ts";
export function cachedDataVersionTag() {
@@ -66,11 +71,11 @@ export function takeCoverage() {
export function writeHeapSnapshot() {
notImplemented("v8.writeHeapSnapshot");
}
-export function serialize() {
- notImplemented("v8.serialize");
+export function serialize(value) {
+ return Buffer.from(core.serialize(value));
}
-export function deserialize() {
- notImplemented("v8.deserialize");
+export function deserialize(data) {
+ return core.deserialize(data);
}
export class Serializer {
constructor() {
diff --git a/tests/unit_node/v8_test.ts b/tests/unit_node/v8_test.ts
index c9697c870..b91d595db 100644
--- a/tests/unit_node/v8_test.ts
+++ b/tests/unit_node/v8_test.ts
@@ -1,7 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import {
cachedDataVersionTag,
+ deserialize,
getHeapStatistics,
+ serialize,
setFlagsFromString,
} from "node:v8";
import { assertEquals } from "@std/assert/mod.ts";
@@ -53,3 +55,12 @@ Deno.test({
setFlagsFromString("--allow_natives_syntax");
},
});
+
+Deno.test({
+ name: "serialize deserialize",
+ fn() {
+ const s = serialize({ a: 1 });
+ const d = deserialize(s);
+ assertEquals(d, { a: 1 });
+ },
+});