Skip to content

Commit

Permalink
[unity]适用于top-level-await的esm实现,fix #1715
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed May 8, 2024
1 parent 49100c0 commit c333e46
Show file tree
Hide file tree
Showing 2 changed files with 369 additions and 333 deletions.
40 changes: 24 additions & 16 deletions unity/native_src/Inc/BackendEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <map>
#include <algorithm>
#include <unordered_map>
#include "Common.h"
#include "Log.h"
#include "V8InspectorImpl.h"
Expand Down Expand Up @@ -101,6 +102,27 @@ namespace PUERTS_NAMESPACE
char* NormalizeModuleName(JSContext *ctx, const char *base_name, const char *name);
#else
std::map<std::string, v8::UniquePersistent<v8::Module>> PathToModuleMap;
struct FModuleInfo
{
v8::Global<v8::Module> Module;
std::map<std::string, v8::Global<v8::Module>> ResolveCache;
};
std::unordered_multimap<int, FModuleInfo*> ScriptIdToModuleInfo;


v8::MaybeLocal<v8::Value> ResolvePath(v8::Isolate* Isolate, v8::Local<v8::Context> Context, v8::Local<v8::Value> Specifier, v8::Local<v8::Value> ReferrerName);

v8::MaybeLocal<v8::Value> ReadFile( v8::Isolate* Isolate, v8::Local<v8::Context> Context, v8::Local<v8::Value> URL, std::string &pathForDebug);

v8::MaybeLocal<v8::Module> FetchModuleTree(v8::Isolate* isolate, v8::Local<v8::Context> context, v8::Local<v8::String> absolute_file_path);

std::unordered_multimap<int, FBackendEnv::FModuleInfo*>::iterator FindModuleInfo(v8::Local<v8::Module> Module);

static v8::MaybeLocal<v8::Module> ResolveModuleCallback(v8::Local<v8::Context> context, v8::Local<v8::String> specifier,
#if V8_94_OR_NEWER
v8::Local<v8::FixedArray> import_attributes, // not implement yet
#endif
v8::Local<v8::Module> referrer);
#endif
std::map<int, std::string> ScriptIdToPathMap;

Expand Down Expand Up @@ -141,26 +163,12 @@ namespace PUERTS_NAMESPACE
namespace esmodule
{
#if !WITH_QUICKJS
v8::MaybeLocal<v8::Module> _ResolveModule(
v8::Local<v8::Context> Context,
v8::Local<v8::String> Specifier,
v8::Local<v8::Value> Referrer,
bool& isFromCache
);

v8::MaybeLocal<v8::Module> ResolveModule( v8::Local<v8::Context> Context, v8::Local<v8::String> Specifier,
#if V8_94_OR_NEWER
v8::Local<v8::FixedArray> ImportAttributes, // not implement yet
#endif
v8::Local<v8::Module> Referrer);

bool LinkModule(v8::Local<v8::Context> Context, v8::Local<v8::Module> RefModule);

#if V8_MAJOR_VERSION >= 10
v8::MaybeLocal<v8::Promise> DynamicImport(v8::Local<v8::Context> Context, v8::Local<v8::Data> HostDefinedOptions,
v8::MaybeLocal<v8::Promise> HostImportModuleDynamically(v8::Local<v8::Context> Context, v8::Local<v8::Data> HostDefinedOptions,
v8::Local<v8::Value> ResourceName, v8::Local<v8::String> Specifier, v8::Local<v8::FixedArray> ImportAssertions);
#else
v8::MaybeLocal<v8::Promise> DynamicImport(v8::Local<v8::Context> Context, v8::Local<v8::ScriptOrModule> Referrer, v8::Local<v8::String> Specifier);
v8::MaybeLocal<v8::Promise> HostImportModuleDynamically(v8::Local<v8::Context> Context, v8::Local<v8::ScriptOrModule> Referrer, v8::Local<v8::String> Specifier);
#endif

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

0 comments on commit c333e46

Please sign in to comment.