forked from denoland/deno_core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
248 lines (235 loc) · 7.61 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
pub mod arena;
mod async_cancel;
mod async_cell;
pub mod cppgc;
pub mod error;
mod error_codes;
mod extension_set;
mod extensions;
mod external;
mod fast_string;
mod feature_checker;
mod flags;
mod gotham_state;
mod inspector;
mod io;
mod module_specifier;
mod modules;
mod normalize_path;
mod ops;
mod ops_builtin;
mod ops_builtin_types;
mod ops_builtin_v8;
mod ops_metrics;
mod path;
mod runtime;
mod source_map;
mod tasks;
mod web_timeout;
// Re-exports
pub use anyhow;
pub use deno_unsync as unsync;
pub use futures;
pub use parking_lot;
pub use serde;
pub use serde_json;
pub use serde_v8;
pub use serde_v8::ByteString;
pub use serde_v8::DetachedBuffer;
pub use serde_v8::JsBuffer;
pub use serde_v8::StringOrBuffer;
pub use serde_v8::ToJsBuffer;
pub use serde_v8::U16String;
pub use sourcemap;
pub use url;
pub use v8;
pub use deno_ops::op2;
pub use crate::async_cancel::CancelFuture;
pub use crate::async_cancel::CancelHandle;
pub use crate::async_cancel::CancelTryFuture;
pub use crate::async_cancel::Cancelable;
pub use crate::async_cancel::Canceled;
pub use crate::async_cancel::TryCancelable;
pub use crate::async_cell::AsyncMut;
pub use crate::async_cell::AsyncMutFuture;
pub use crate::async_cell::AsyncRef;
pub use crate::async_cell::AsyncRefCell;
pub use crate::async_cell::AsyncRefFuture;
pub use crate::async_cell::RcLike;
pub use crate::async_cell::RcRef;
pub use crate::error::GetErrorClassFn;
pub use crate::error::JsErrorCreateFn;
pub use crate::extensions::Extension;
pub use crate::extensions::ExtensionFileSource;
pub use crate::extensions::ExtensionFileSourceCode;
pub use crate::extensions::Op;
pub use crate::extensions::OpDecl;
pub use crate::extensions::OpMiddlewareFn;
pub use crate::external::ExternalDefinition;
pub use crate::external::ExternalPointer;
pub use crate::external::Externalizable;
pub use crate::fast_string::FastString;
pub use crate::feature_checker::FeatureChecker;
pub use crate::flags::v8_set_flags;
pub use crate::inspector::InspectorMsg;
pub use crate::inspector::InspectorMsgKind;
pub use crate::inspector::InspectorSessionProxy;
pub use crate::inspector::JsRuntimeInspector;
pub use crate::inspector::LocalInspectorSession;
pub use crate::io::AsyncResult;
pub use crate::io::BufMutView;
pub use crate::io::BufMutViewWhole;
pub use crate::io::BufView;
pub use crate::io::Resource;
pub use crate::io::ResourceHandle;
pub use crate::io::ResourceHandleFd;
pub use crate::io::ResourceHandleSocket;
pub use crate::io::ResourceId;
pub use crate::io::ResourceTable;
pub use crate::io::WriteOutcome;
pub use crate::module_specifier::resolve_import;
pub use crate::module_specifier::resolve_path;
pub use crate::module_specifier::resolve_url;
pub use crate::module_specifier::resolve_url_or_path;
pub use crate::module_specifier::ModuleResolutionError;
pub use crate::module_specifier::ModuleSpecifier;
pub use crate::modules::CustomModuleEvaluationKind;
pub use crate::modules::ExtModuleLoaderCb;
pub use crate::modules::FsModuleLoader;
pub use crate::modules::ModuleCodeBytes;
pub use crate::modules::ModuleCodeString;
pub use crate::modules::ModuleId;
pub use crate::modules::ModuleLoadResponse;
pub use crate::modules::ModuleLoader;
pub use crate::modules::ModuleSource;
pub use crate::modules::ModuleSourceCode;
pub use crate::modules::ModuleSourceFuture;
pub use crate::modules::ModuleType;
pub use crate::modules::NoopModuleLoader;
pub use crate::modules::RequestedModuleType;
pub use crate::modules::ResolutionKind;
pub use crate::modules::StaticModuleLoader;
pub use crate::modules::ValidateImportAttributesCb;
pub use crate::normalize_path::normalize_path;
pub use crate::ops::OpId;
pub use crate::ops::OpState;
pub use crate::ops::PromiseId;
pub use crate::ops_builtin::op_close;
pub use crate::ops_builtin::op_print;
pub use crate::ops_builtin::op_resources;
pub use crate::ops_builtin::op_void_async;
pub use crate::ops_builtin::op_void_sync;
pub use crate::ops_metrics::merge_op_metrics;
pub use crate::ops_metrics::OpMetricsEvent;
pub use crate::ops_metrics::OpMetricsFactoryFn;
pub use crate::ops_metrics::OpMetricsFn;
pub use crate::ops_metrics::OpMetricsSource;
pub use crate::ops_metrics::OpMetricsSummary;
pub use crate::ops_metrics::OpMetricsSummaryTracker;
pub use crate::path::strip_unc_prefix;
pub use crate::runtime::stats;
pub use crate::runtime::CompiledWasmModuleStore;
pub use crate::runtime::CreateRealmOptions;
pub use crate::runtime::CrossIsolateStore;
pub use crate::runtime::JsRuntime;
pub use crate::runtime::JsRuntimeForSnapshot;
pub use crate::runtime::PollEventLoopOptions;
pub use crate::runtime::RuntimeOptions;
pub use crate::runtime::SharedArrayBufferStore;
pub use crate::runtime::V8_WRAPPER_OBJECT_INDEX;
pub use crate::runtime::V8_WRAPPER_TYPE_INDEX;
pub use crate::source_map::SourceMapGetter;
pub use crate::tasks::V8CrossThreadTaskSpawner;
pub use crate::tasks::V8TaskSpawner;
// Ensure we can use op2 in deno_core without any hackery.
extern crate self as deno_core;
pub fn v8_version() -> &'static str {
v8::V8::get_version()
}
/// An internal module re-exporting functions used by the #[op] (`deno_ops`) macro
#[doc(hidden)]
pub mod _ops {
pub use super::error::throw_type_error;
pub use super::error_codes::get_error_code;
pub use super::extensions::Op;
pub use super::extensions::OpDecl;
#[cfg(debug_assertions)]
pub use super::ops::reentrancy_check;
pub use super::ops::OpCtx;
pub use super::ops_metrics::dispatch_metrics_async;
pub use super::ops_metrics::dispatch_metrics_fast;
pub use super::ops_metrics::dispatch_metrics_slow;
pub use super::ops_metrics::OpMetricsEvent;
pub use super::runtime::ops::*;
pub use super::runtime::ops_rust_to_v8::*;
pub use super::runtime::V8_WRAPPER_OBJECT_INDEX;
pub use super::runtime::V8_WRAPPER_TYPE_INDEX;
}
pub mod snapshot {
pub use crate::runtime::create_snapshot;
pub use crate::runtime::get_js_files;
pub use crate::runtime::CreateSnapshotOptions;
pub use crate::runtime::CreateSnapshotOutput;
pub use crate::runtime::FilterFn;
}
/// A helper macro that will return a call site in Rust code. Should be
/// used when executing internal one-line scripts for JsRuntime lifecycle.
///
/// Returns a string in form of: "`[ext:<filename>:<line>:<column>]`"
#[macro_export]
macro_rules! located_script_name {
() => {
concat!(
"[ext:",
::std::file!(),
":",
::std::line!(),
":",
::std::column!(),
"]"
)
};
}
#[cfg(all(test, not(miri)))]
mod tests {
use std::process::Command;
use std::process::Stdio;
use super::*;
#[test]
fn located_script_name() {
// Note that this test will fail if this file is moved. We don't
// test line locations because that's just too brittle.
let name = located_script_name!();
let expected = if cfg!(windows) {
"[ext:core\\lib.rs:"
} else {
"[ext:core/lib.rs:"
};
assert_eq!(&name[..expected.len()], expected);
}
#[test]
fn test_v8_version() {
assert!(v8_version().len() > 3);
}
// If the deno command is available, we ensure the async stubs are correctly rebuilt.
#[test]
fn test_rebuild_async_stubs() {
// Check for deno first
if let Err(e) = Command::new("deno")
.arg("--version")
.stderr(Stdio::null())
.stdout(Stdio::null())
.status()
{
eprintln!("Ignoring test because we couldn't find deno: {e:?}");
}
let status = Command::new("deno")
.args(["run", "-A", "rebuild_async_stubs.js", "--check"])
.stderr(Stdio::null())
.stdout(Stdio::null())
.status()
.unwrap();
assert!(status.success(), "Async stubs were not updated, or 'rebuild_async_stubs.js' failed for some other reason");
}
}