Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions NativeScript/runtime/ModuleInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ class ModuleInternal {
const std::string& path,
std::string* rejectionReason);

// A code-cache blob is either a script blob or a module blob, and V8 rejects
// the wrong kind outright. One file compiled both ways — require('./x.js')
// and import './x.js' — would otherwise share a blob and each load would
// reject and overwrite the other's, so the two kinds get their own suffix
// and the cache actually hits.
enum class ScriptCacheKind { kClassicScript, kEsModule };
// The blob for `path` when one was written for the file's modification time
// `sourceModifiedTime`, otherwise empty. Stats only; never reads the blob.
// Always empty in the development flavor, which never consumes a cache.
static std::string FreshScriptCachePath(const std::string& path,
ScriptCacheKind kind,
time_t sourceModifiedTime);
// Queues creation of the code cache for a script compiled from `path` as
// it was at `sourceModifiedTime`. Creation needs the isolate's thread and
// costs a fifth of a cold compile, so it runs later in short slices once
// loading goes quiet (or when the app moves to the background); the file is
// written off-thread, and skipped if the source changed since it was read.
// A no-op in the development flavor. Isolate thread only.
static void QueueScriptCache(v8::Isolate* isolate,
v8::Local<v8::UnboundModuleScript> script,
const std::string& path,
time_t sourceModifiedTime);
static void QueueScriptCache(v8::Isolate* isolate,
v8::Local<v8::UnboundScript> script,
const std::string& path,
time_t sourceModifiedTime);
// Where the code cache for `path` (with its kind's suffix) lives.
static std::string GetCacheFileName(const std::string& path);

private:
static void RequireCallback(const v8::FunctionCallbackInfo<v8::Value>& info);
static void CreateRequireCallback(
Expand Down Expand Up @@ -137,19 +166,8 @@ class ModuleInternal {
const std::string& moduleName);
std::string ResolvePathFromPackageJson(const std::string& packageJson,
bool& error);
// A code-cache blob is either a script blob or a module blob, and V8 rejects
// the wrong kind outright. One file compiled both ways — require('./x.js')
// and import './x.js' — would otherwise share a blob and each load would
// reject and overwrite the other's, so the two kinds get their own suffix
// and the cache actually hits.
enum class ScriptCacheKind { kClassicScript, kEsModule };
static v8::ScriptCompiler::CachedData* LoadScriptCache(
const std::string& path, ScriptCacheKind kind);
static void SaveScriptCache(const v8::Local<v8::Script> script,
const std::string& path);
static void SaveScriptCache(const v8::ScriptCompiler::CachedData* cache,
const std::string& path, ScriptCacheKind kind);
static std::string GetCacheFileName(const std::string& path);
const std::string& path, ScriptCacheKind kind, time_t sourceModifiedTime);
v8::MaybeLocal<v8::Value> RunScriptString(v8::Isolate* isolate,
v8::Local<v8::Context> context,
const std::string script);
Expand Down
Loading
Loading