summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/lib.rs3
-rw-r--r--ext/node/polyfills/v8.ts27
-rw-r--r--ext/node/v8.rs29
3 files changed, 57 insertions, 2 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index f4c23a16a..cb273ef9e 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -20,6 +20,7 @@ mod package_json;
mod path;
mod polyfill;
mod resolution;
+mod v8;
mod winerror;
pub use package_json::PackageJson;
@@ -413,6 +414,8 @@ pub fn init_polyfill() -> Extension {
crypto::op_node_hash_digest::decl(),
crypto::op_node_hash_clone::decl(),
winerror::op_node_sys_to_uv_error::decl(),
+ v8::op_v8_cached_data_version_tag::decl(),
+ v8::op_v8_get_heap_statistics::decl(),
op_node_build_os::decl(),
])
.build()
diff --git a/ext/node/polyfills/v8.ts b/ext/node/polyfills/v8.ts
index f186ff023..c7875e654 100644
--- a/ext/node/polyfills/v8.ts
+++ b/ext/node/polyfills/v8.ts
@@ -3,8 +3,10 @@
import { notImplemented } from "internal:deno_node/polyfills/_utils.ts";
+const { ops } = globalThis.__bootstrap.core;
+
export function cachedDataVersionTag() {
- notImplemented("v8.cachedDataVersionTag");
+ return ops.op_v8_cached_data_version_tag();
}
export function getHeapCodeStatistics() {
notImplemented("v8.getHeapCodeStatistics");
@@ -15,9 +17,30 @@ export function getHeapSnapshot() {
export function getHeapSpaceStatistics() {
notImplemented("v8.getHeapSpaceStatistics");
}
+
+const buffer = new Float64Array(14);
+
export function getHeapStatistics() {
- notImplemented("v8.getHeapStatistics");
+ ops.op_v8_get_heap_statistics(buffer);
+
+ return {
+ total_heap_size: buffer[0],
+ total_heap_size_executable: buffer[1],
+ total_physical_size: buffer[2],
+ total_available_size: buffer[3],
+ used_heap_size: buffer[4],
+ heap_size_limit: buffer[5],
+ malloced_memory: buffer[6],
+ peak_malloced_memory: buffer[7],
+ does_zap_garbage: buffer[8],
+ number_of_native_contexts: buffer[9],
+ number_of_detached_contexts: buffer[10],
+ total_global_handles_size: buffer[11],
+ used_global_handles_size: buffer[12],
+ external_memory: buffer[13],
+ };
}
+
export function setFlagsFromString() {
notImplemented("v8.setFlagsFromString");
}
diff --git a/ext/node/v8.rs b/ext/node/v8.rs
new file mode 100644
index 000000000..5307f7107
--- /dev/null
+++ b/ext/node/v8.rs
@@ -0,0 +1,29 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use deno_core::op;
+use deno_core::v8;
+
+#[op]
+fn op_v8_cached_data_version_tag() -> u32 {
+ v8::script_compiler::cached_data_version_tag()
+}
+
+#[op(v8)]
+fn op_v8_get_heap_statistics(scope: &mut v8::HandleScope, buffer: &mut [f64]) {
+ let mut stats = v8::HeapStatistics::default();
+ scope.get_heap_statistics(&mut stats);
+
+ buffer[0] = stats.total_heap_size() as f64;
+ buffer[1] = stats.total_heap_size_executable() as f64;
+ buffer[2] = stats.total_physical_size() as f64;
+ buffer[3] = stats.total_available_size() as f64;
+ buffer[4] = stats.used_heap_size() as f64;
+ buffer[5] = stats.heap_size_limit() as f64;
+ buffer[6] = stats.malloced_memory() as f64;
+ buffer[7] = stats.peak_malloced_memory() as f64;
+ buffer[8] = stats.does_zap_garbage() as f64;
+ buffer[9] = stats.number_of_native_contexts() as f64;
+ buffer[10] = stats.number_of_detached_contexts() as f64;
+ buffer[11] = stats.total_global_handles_size() as f64;
+ buffer[12] = stats.used_global_handles_size() as f64;
+ buffer[13] = stats.external_memory() as f64;
+}