Skip to content

Commit 2a07036

Browse files
authored
Refactor and extract call_reducer and update_database machinery for reuse by V8 (#3190)
# Description of Changes Refactors the machinery of call_reducer and update_database to a) have smaller pieces that make up the whole so that the code becomes clearer b) extract all the VM-independent stuff so that it can be reused by V8 modules. This is best reviewed commit by commit. # API and ABI breaking changes None. # Expected complexity level and risk 2, it's an important place, but this is doing just code motion. # Testing No semantic changes, just code motion.
1 parent be1bd22 commit 2a07036

File tree

4 files changed

+246
-142
lines changed

4 files changed

+246
-142
lines changed

crates/core/src/host/v8/key_cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(super) struct KeyCache {
2222
tag: Option<Global<v8::String>>,
2323
/// The `value` property for sum values in JS.
2424
value: Option<Global<v8::String>>,
25-
/// The `describe_module` property on the global proxy object.
25+
/// The `__describe_module__` property on the global proxy object.
2626
describe_module: Option<Global<v8::String>>,
2727
}
2828

@@ -37,9 +37,9 @@ impl KeyCache {
3737
Self::get_or_create_key(scope, &mut self.value, "value")
3838
}
3939

40-
/// Returns the `describe_module` property name.
40+
/// Returns the `__describe_module__` property name.
4141
pub(super) fn describe_module<'scope>(&mut self, scope: &mut HandleScope<'scope>) -> Local<'scope, v8::String> {
42-
Self::get_or_create_key(scope, &mut self.describe_module, "describe_module")
42+
Self::get_or_create_key(scope, &mut self.describe_module, "__describe_module__")
4343
}
4444

4545
/// Returns an interned string corresponding to `string`

crates/core/src/host/v8/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ impl ModuleInstance for JsInstance {
134134
}
135135
}
136136

137-
// Calls the `describe_module` function on the global proxy object to extract a [`RawModuleDef`].
137+
// Calls the `__describe_module__` function on the global proxy object to extract a [`RawModuleDef`].
138138
fn call_describe_module(scope: &mut HandleScope<'_>) -> anyhow::Result<RawModuleDef> {
139-
// Get a cached version of the `describe_module` property.
139+
// Get a cached version of the `__describe_module__` property.
140140
let key_cache = get_or_create_key_cache(scope);
141141
let describe_module_key = key_cache.borrow_mut().describe_module(scope).into();
142142

@@ -150,7 +150,7 @@ fn call_describe_module(scope: &mut HandleScope<'_>) -> anyhow::Result<RawModule
150150

151151
// Convert to a function.
152152
let fun =
153-
cast!(scope, object, Function, "function export for `describe_module`").map_err(|e| e.throw(scope))?;
153+
cast!(scope, object, Function, "function export for `__describe_module__`").map_err(|e| e.throw(scope))?;
154154

155155
// Call the function.
156156
let receiver = v8::undefined(scope).into();
@@ -183,7 +183,7 @@ mod test {
183183
#[test]
184184
fn call_describe_module_works() {
185185
let code = r#"
186-
function describe_module() {
186+
function __describe_module__() {
187187
return {
188188
"tag": "V9",
189189
"value": {

0 commit comments

Comments
 (0)