@@ -6,7 +6,9 @@ use nova_vm::{
66 ecmascript:: {
77 builtins:: { Behaviour , BuiltinFunctionArgs , RegularFn , create_builtin_function} ,
88 execution:: Agent ,
9- scripts_and_modules:: script:: { parse_script, script_evaluation} ,
9+ scripts_and_modules:: {
10+ module:: module_semantics:: source_text_module_records:: parse_module, script:: HostDefined ,
11+ } ,
1012 types:: { InternalMethods , IntoValue , Object , PropertyDescriptor , PropertyKey } ,
1113 } ,
1214 engine:: context:: { Bindable , GcScope } ,
@@ -57,32 +59,34 @@ impl Extension {
5759 andromeda_object : Object ,
5860 gc : & mut GcScope < ' _ , ' _ > ,
5961 ) {
60- for file in & self . files {
61- let source_text = nova_vm:: ecmascript:: types:: String :: from_str ( agent, file, gc. nogc ( ) ) ;
62- let script = match parse_script (
62+ for ( idx, file_source) in self . files . iter ( ) . enumerate ( ) {
63+ let specifier = format ! ( "<ext:{}:{}>" , self . name, idx) ;
64+ let source_text =
65+ nova_vm:: ecmascript:: types:: String :: from_str ( agent, file_source, gc. nogc ( ) ) ;
66+
67+ let module = match parse_module (
6368 agent,
6469 source_text,
6570 agent. current_realm ( gc. nogc ( ) ) ,
66- true ,
67- None ,
71+ Some ( std:: rc:: Rc :: new ( specifier. clone ( ) ) as HostDefined ) ,
6872 gc. nogc ( ) ,
6973 ) {
70- Ok ( script ) => script ,
71- Err ( diagnostics) => exit_with_parse_errors ( diagnostics, "<runtime>" , file ) ,
74+ Ok ( module ) => module ,
75+ Err ( diagnostics) => exit_with_parse_errors ( diagnostics, & specifier , file_source ) ,
7276 } ;
73- let eval_result = script_evaluation ( agent , script . unbind ( ) , gc . reborrow ( ) ) . unbind ( ) ;
74- match eval_result {
75- Ok ( _ ) => ( ) ,
76- Err ( e ) => {
77- let error_value = e . value ( ) ;
78- let message = error_value
79- . string_repr ( agent , gc . reborrow ( ) )
80- . as_str ( agent)
81- . unwrap_or ( "<non-string error>" )
82- . to_string ( ) ;
83- let err = AndromedaError :: runtime_error ( message ) ;
84- print_enhanced_error ( & err ) ;
85- }
77+
78+ let eval_result = agent
79+ . run_parsed_module ( module . unbind ( ) , None , gc . reborrow ( ) )
80+ . unbind ( ) ;
81+ if let Err ( e ) = eval_result {
82+ let error_value = e . value ( ) ;
83+ let message = error_value
84+ . string_repr ( agent, gc . reborrow ( ) )
85+ . as_str ( agent )
86+ . unwrap_or ( "<non-string error>" )
87+ . to_string ( ) ;
88+ let err = AndromedaError :: runtime_error ( message ) ;
89+ print_enhanced_error ( & err ) ;
8690 }
8791 }
8892 for op in & self . ops {
0 commit comments