Hi Ronald, I'm having a hard-time understanding exactly where you create the TestObj class/constructor since much of your implementation seems to be hidden in JSModules and JSModulesTestInternal Could you maybe create an example of your issue with pure V8 API?
cheers, Camillo On Sat, 28 Aug 2021 at 21:45, Ronald Fenner <rfen...@gamecircus.com> wrote: > I'm trying to test a JS Module that creates a new object that's been > registered from the C++ side but it fails on evaluation with: > Reference Error: TestObj is not defined. > > I can run a script that does essentially the same thing as the module and > it's able to run successfully and trigger the C++ function for the > construction of the object. > > Here's the test code > > v8::HandleScope handleScope(m_Isolate); > JSContext *jsContext = m_Context.lock().get(); > WeakJSModulesPtr weakJSModules = jsContext->GetModules(); > JSModules *jsModules = weakJSModules.lock().get(); > > JSModulesTestInternal::TestObject::BuildObjectTemplate(m_Isolate); > > const char source[] = R"script( > let obj = new TestObject(); > )script"; > v8::Local<v8::String> v8Source = JSUtilities::StringToV8(m_Isolate, > source); > EXPECT_FALSE(v8Source.IsEmpty()); > > v8::TryCatch tryCatch(m_Isolate); > > v8::Local<v8::Script> script = > v8::Script::Compile(jsContext->GetContext(), v8Source).ToLocalChecked(); > script->Run(jsContext->GetContext()); > if (tryCatch.HasCaught()) > { > std::string error = JSUtilities::GetStackTrace(m_Isolate, tryCatch); > std::cout << "Script Error: " << error << std::endl; > ASSERT_TRUE(false); > } > > EXPECT_NE(nullptr, JSModulesTestInternal::constructerCreatedObjectTest); > JSModulesTestInternal::constructerCreatedObjectTest) = nullptr; > > //test that module can't be instantiate cause imported module isn't loaded > v8::Local<v8::Module> root; > v8::MaybeLocal<v8::Module> maybeRoot = jsModules->LoadModule("root.mjs"); > EXPECT_TRUE(maybeRoot.ToLocal(&root)); > ASSERT_FALSE(root.IsEmpty()); > > EXPECT_TRUE(jsModules->InstantiateModule(root)); > > EXPECT_TRUE(jsModules->RunModule(root)); // Fails here. > > ASSERT_NE(nullptr, JSModulesTestInternal::constructerCreatedObjectTest); > > EXPECT_EQ(5, > JSModulesTestInternal::constructerCreatedObjectTest->GetValue()); > > Here's the modules code > import rootImport from 'sub-dir/rootImport' > > let obj = new TestObj(); > obj.value = 5; > > > -- > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to v8-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/v8-users/fbbc9546-d83a-4195-983a-db773d6a1745n%40googlegroups.com > <https://groups.google.com/d/msgid/v8-users/fbbc9546-d83a-4195-983a-db773d6a1745n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > Camillo Bruni | Software Engineer, V8 | Google Germany GmbH | Erika-Mann Str. 33, 80636 München Registergericht und -nummer: Hamburg, HRB 86891 | Sitz der Gesellschaft: Hamburg | Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Diese E-Mail ist vertraulich. Falls Ssie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person. -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/CAOeS1i8KVkXfQJ8mP2DxW13PNaCbxUO_Ms5jugUGXdgOHWv75Q%40mail.gmail.com.