Skip to content

Commit ea94b24

Browse files
committed
fix: repl
1 parent 7001b23 commit ea94b24

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = ["the Andromeda team"]
77
edition = "2024"
88
license = "Mozilla Public License 2.0"
99
repository = "https://github.com/tryandromeda/andromeda"
10-
version = "0.1.0-draft39"
10+
version = "0.1.0-draft40"
1111

1212
[workspace.dependencies]
1313
andromeda-core = { path = "core" }

cli/src/repl.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use nova_vm::{
1919
Agent, JsResult,
2020
agent::{GcAgent, Options},
2121
},
22-
scripts_and_modules::script::{parse_script, script_evaluation},
22+
scripts_and_modules::{
23+
module::module_semantics::source_text_module_records::parse_module,
24+
script::{parse_script, script_evaluation},
25+
},
2326
types::{
2427
self, InternalMethods, IntoValue, Object, OrdinaryObject, PropertyDescriptor,
2528
PropertyKey, Value,
@@ -287,25 +290,25 @@ fn initialize_global_object(agent: &mut Agent, global_object: Object, mut gc: Gc
287290

288291
let mut extensions = recommended_extensions();
289292
for extension in &mut extensions {
290-
for file in &extension.files {
293+
for (idx, file) in extension.files.iter().enumerate() {
294+
let specifier = format!("<ext:{}:{}>", extension.name, idx);
291295
let source_text = types::String::from_str(agent, file, gc.nogc());
292-
let script = match parse_script(
296+
let module = match parse_module(
293297
agent,
294298
source_text,
295299
agent.current_realm(gc.nogc()),
296-
true,
297-
None,
300+
Some(std::rc::Rc::new(specifier.clone())),
298301
gc.nogc(),
299302
) {
300-
Ok(script) => script,
303+
Ok(module) => module,
301304
Err(errors) => {
302-
handle_parse_errors(errors, "<extension>", file);
305+
handle_parse_errors(errors, &specifier, file);
303306
std::process::exit(1);
304307
}
305308
};
306-
if script_evaluation(agent, script.unbind(), gc.reborrow()).is_err() {
307-
eprintln!("⚠️ Warning: Error loading extension");
308-
handle_runtime_error_with_message("Script evaluation failed".to_string());
309+
if agent.run_parsed_module(module.unbind(), None, gc.reborrow()).unbind().is_err() {
310+
eprintln!("⚠️ Warning: Error loading extension {}", specifier);
311+
handle_runtime_error_with_message("Module evaluation failed".to_string());
309312
}
310313
}
311314
// Register native ops

namespace/mod.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ const Andromeda = {
733733
// If no more listeners, unregister the native handler
734734
if (listeners.size === 0) {
735735
signalListeners.delete(signal);
736-
internal_remove_signal_listener(signal, () => {});
736+
__andromeda__.internal_remove_signal_listener(signal, () => {});
737737
}
738738
}
739739
},
@@ -762,7 +762,11 @@ const Andromeda = {
762762
*/
763763
get serve() {
764764
// @ts-ignore - internal use
765-
return globalThis.__andromeda_http_serve;
765+
const httpServe = globalThis.__andromeda_http_serve;
766+
if (typeof httpServe !== "function") {
767+
throw new Error("HTTP extension is not available. Make sure the 'serve' feature is enabled.");
768+
}
769+
return httpServe;
766770
},
767771
};
768772

@@ -890,4 +894,9 @@ function decodeURI(input: string): string {
890894
}
891895

892896
// Export Andromeda globally
893-
(globalThis as any).Andromeda = Andromeda;
897+
Object.defineProperty(globalThis, "Andromeda", {
898+
value: Andromeda,
899+
writable: false,
900+
enumerable: true,
901+
configurable: false,
902+
});

runtime/src/ext/http/mod.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
// This Source Code Form is subject to the terms of the Mozilla Public
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4-
5-
// deno-lint-ignore-file no-explicit-any
6-
7-
// Import existing Request/Response implementations
8-
// These are loaded by the fetch extension, so we don't need to import them here
9-
104
export interface ServeHandler {
115
(request: Request): Response | Promise<Response>;
126
}
@@ -23,7 +17,7 @@ export interface ServeInit extends ServeOptions {
2317

2418
export interface HttpServer {
2519
finished: Promise<void>;
26-
shutdown(): Promise<void>;
20+
shutdown(): void;
2721
unref(): void;
2822
ref(): void;
2923
}
@@ -43,10 +37,10 @@ export function serve(handler: ServeHandler | ServeInit): HttpServer {
4337
serverHandlers.set(serverId, options.handler);
4438

4539
return {
46-
finished: new Promise((resolve) => {
40+
finished: new Promise((_resolve) => {
4741
// TODO: Track server lifecycle
4842
}),
49-
shutdown: async () => {
43+
shutdown: () => {
5044
__andromeda__.internal_http_close(serverId);
5145
serverHandlers.delete(serverId);
5246
},
@@ -59,6 +53,8 @@ export function serve(handler: ServeHandler | ServeInit): HttpServer {
5953
};
6054
}
6155

62-
// Export serve function globally for namespace to pick up
63-
// @ts-ignore - internal use
64-
globalThis.__andromeda_http_serve = serve;
56+
// Store serve function for namespace access, but use a safer approach
57+
if (typeof globalThis === "object" && globalThis) {
58+
// @ts-ignore - internal use
59+
globalThis.__andromeda_http_serve = serve;
60+
}

0 commit comments

Comments
 (0)