Skip to content

Commit

Permalink
[unity]qucikjs后端的esm实现改为纯js api实现,fix #1694
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Apr 10, 2024
1 parent 2881eac commit 573e400
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 144 deletions.
18 changes: 14 additions & 4 deletions unity/native_src/Inc/BackendEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ namespace PUERTS_NAMESPACE
// Module
#if defined(WITH_QUICKJS)
std::map<std::string, JSModuleDef*> PathToModuleMap;
JSValue JsFileLoader;
JSValue JsFileNormalize;

JSModuleDef* LoadModule(JSContext* ctx, const char *name);

char* ResolveQjsModule(JSContext *ctx, const char *base_name, const char *name, bool throwIfFail);

char* NormalizeModuleName(JSContext *ctx, const char *base_name, const char *name);
#else
std::map<std::string, v8::UniquePersistent<v8::Module>> PathToModuleMap;
#endif
Expand Down Expand Up @@ -130,8 +138,6 @@ namespace PUERTS_NAMESPACE

namespace esmodule
{
void ExecuteModule(const v8::FunctionCallbackInfo<v8::Value>& info);

#if !WITH_QUICKJS
v8::MaybeLocal<v8::Module> _ResolveModule(
v8::Local<v8::Context> Context,
Expand All @@ -147,10 +153,14 @@ namespace PUERTS_NAMESPACE
v8::MaybeLocal<v8::Promise> DynamicImport(v8::Local<v8::Context> Context, v8::Local<v8::ScriptOrModule> Referrer, v8::Local<v8::String> Specifier);

void HostInitializeImportMetaObject(v8::Local<v8::Context> Context, v8::Local<v8::Module> Module, v8::Local<v8::Object> meta);

void ExecuteModule(const v8::FunctionCallbackInfo<v8::Value>& info);
#else
JSModuleDef* js_module_loader(JSContext* ctx, const char *name, void *opaque);

char* js_module_resolver(JSContext *ctx, const char *base_name, const char *name, void* opaque);

char* module_normalize(JSContext *ctx, const char *base_name, const char *name, void* opaque);

JSValue ExecuteModule(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data);
#endif
}
}
Loading

0 comments on commit 573e400

Please sign in to comment.