@@ -11,6 +11,7 @@ use std::path::Path;
1111use crate :: deno:: error:: Error ;
1212use crate :: deno:: runtime:: Runtime ;
1313use crate :: deno:: traits:: { ToDefinedValue , ToV8String } ;
14+ use crate :: deno_println;
1415
1516#[ derive( Debug , Clone ) ]
1617pub struct Module {
@@ -64,9 +65,10 @@ fn resolve_path(
6465 path_str : impl AsRef < Path > ,
6566 current_dir : & Path ,
6667) -> Result < ModuleSpecifier , JsErrorBox > {
68+ use std:: borrow:: Cow ;
6769 let path = current_dir. join ( path_str) ;
68- let path = deno_core:: normalize_path ( path) ;
69- deno_core:: url:: Url :: from_file_path ( & path) . map_err ( |( ) | {
70+ let path = deno_core:: normalize_path ( Cow :: Borrowed ( path. as_path ( ) ) ) ;
71+ deno_core:: url:: Url :: from_file_path ( path. as_ref ( ) ) . map_err ( |( ) | {
7072 JsErrorBox :: generic ( format ! (
7173 "Failed to resolve path: {}" ,
7274 path. to_string_lossy( ) . to_string( )
@@ -109,7 +111,12 @@ impl ModuleHandle {
109111 ) -> Result < v8:: Global < v8:: Function > , Error > {
110112 let value = self . get_value_ref ( runtime, name) ?;
111113
112- let mut scope = runtime. deno_runtime ( ) . handle_scope ( ) ;
114+ let deno_runtime = runtime. deno_runtime ( ) ;
115+ let context = deno_runtime. main_context ( ) ;
116+ let isolate = deno_runtime. v8_isolate ( ) ;
117+ v8:: scope!( handle_scope, isolate) ;
118+ let context_local = v8:: Local :: new ( handle_scope, context) ;
119+ let mut scope = v8:: ContextScope :: new ( handle_scope, context_local) ;
113120 let local = v8:: Local :: < v8:: Value > :: new ( & mut scope, value) ;
114121
115122 if !local. is_function ( ) {
@@ -141,11 +148,18 @@ impl ModuleHandle {
141148 ) ) ;
142149 } ;
143150
144- let mut scope = runtime. deno_runtime ( ) . handle_scope ( ) ;
151+ let deno_runtime = runtime. deno_runtime ( ) ;
152+ let context = deno_runtime. main_context ( ) ;
153+ let isolate = deno_runtime. v8_isolate ( ) ;
154+ v8:: scope!( handle_scope, isolate) ;
155+ let context_local = v8:: Local :: new ( handle_scope, context) ;
156+ let mut scope = v8:: ContextScope :: new ( handle_scope, context_local) ;
145157 let module_namespace = module_namespace. open ( & mut scope) ;
146158 assert ! ( module_namespace. is_module_namespace_object( ) ) ;
147159
148- let key = name. to_v8_string ( & mut scope) ?. cast :: < v8:: Value > ( ) ;
160+ let key = v8:: String :: new ( & scope, name)
161+ . ok_or_else ( || Error :: V8Encoding ( name. to_string ( ) ) ) ?
162+ . cast :: < v8:: Value > ( ) ;
149163 let value = module_namespace. get ( & mut scope, key) ;
150164
151165 match value. if_defined ( ) {
@@ -155,14 +169,25 @@ impl ModuleHandle {
155169 }
156170
157171 pub fn get_module_exports ( & self , runtime : & mut Runtime ) -> Result < Vec < String > , Error > {
172+ println ! ( "[DEBUG] get_module_exports: trying to get namespace for module_id: {}" , self . module_id) ;
173+
158174 let module_namespace =
159175 if let Ok ( namespace) = runtime. deno_runtime ( ) . get_module_namespace ( self . module_id ) {
176+ println ! ( "[DEBUG] get_module_exports: successfully got namespace" ) ;
160177 namespace
161178 } else {
179+ println ! ( "[DEBUG] get_module_exports: failed to get namespace for module_id: {}" , self . module_id) ;
180+ // Try to get more information about why it failed
181+ eprintln ! ( "[DEBUG] Module {} namespace not available - module may not be fully evaluated" , self . module_id) ;
162182 return Err ( Error :: Runtime ( self . module_id ( ) . to_string ( ) ) ) ;
163183 } ;
164184
165- let mut scope = runtime. deno_runtime ( ) . handle_scope ( ) ;
185+ let deno_runtime = runtime. deno_runtime ( ) ;
186+ let context = deno_runtime. main_context ( ) ;
187+ let isolate = deno_runtime. v8_isolate ( ) ;
188+ v8:: scope!( handle_scope, isolate) ;
189+ let context_local = v8:: Local :: new ( handle_scope, context) ;
190+ let mut scope = v8:: ContextScope :: new ( handle_scope, context_local) ;
166191 let module_namespace = module_namespace. open ( & mut scope) ;
167192 assert ! ( module_namespace. is_module_namespace_object( ) ) ;
168193
0 commit comments