Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0cd5c7f
build(runtime): take the base64 codec from the shared runtime-common …
edusperoni Dec 4, 2026
1624660
feat(runtime): run the HTTP module loader on runtime-common
edusperoni Dec 5, 2026
2108347
build: pin runtime-common foundation and implement its platform funct…
edusperoni Dec 5, 2026
89b9580
feat(runtime): pump through Loop::PumpUntil
edusperoni Dec 5, 2026
2a2d735
fix(runtime): termination always ends a module load with a throw
edusperoni Dec 5, 2026
31b4eaa
build: pin runtime-common at ebb7b87
edusperoni Dec 5, 2026
2f63376
fix(runtime): V8 callbacks throw on Terminated instead of returning
edusperoni Dec 5, 2026
b6fd4b1
build: pin runtime-common at 95d96cc and implement its app-file seam
edusperoni Dec 5, 2026
32ab7ec
feat(runtime): give the code cache a directory of its own
edusperoni Dec 5, 2026
88d3a22
feat(runtime): compile app files and keep code caches through the sha…
edusperoni Dec 5, 2026
4f94119
feat(runtime): remove the code caches older runtimes left beside sources
edusperoni Dec 5, 2026
ce8edad
build: pin runtime-common at 6826386
edusperoni Dec 5, 2026
9e562df
test: let in-flight cache writes finish before checking for temporaries
edusperoni Dec 5, 2026
71a1da0
build: pin runtime-common at 39e2174 and implement its URL parser seam
edusperoni Dec 5, 2026
85a53ba
test: pin the verbatim spelling of module and script URLs
edusperoni Dec 5, 2026
4bc5dcb
feat(runtime): name modules through the shared core's module identity
edusperoni Dec 5, 2026
e9158bb
build: pin runtime-common at 3bcf603
edusperoni Dec 5, 2026
03d1633
feat(runtime): give each isolate a loader config snapshot
edusperoni Dec 5, 2026
5e3390c
feat(runtime): load modules through the shared core's registry and re…
edusperoni Dec 5, 2026
f5ed9fc
test(runtime): pin the shared resolver's specifier rules
edusperoni Dec 5, 2026
60a6ac9
build: pin runtime-common at da7852d
edusperoni Dec 5, 2026
1ee254f
fix(runtime): prefilter blob: URLs on the whole scheme
edusperoni Dec 5, 2026
63ac13e
test(runtime): pin the reviewed resolver rules
edusperoni Dec 6, 2026
83a7256
test(runtime): benchmark import() through the module loader
edusperoni Dec 6, 2026
d07ac5d
build: pin runtime-common at 8585d65
edusperoni Dec 6, 2026
8d5168e
refactor(runtime): load and import modules through runtime-common
edusperoni Dec 6, 2026
495d00d
test(runtime): JSON module strictness and import() while a worker closes
edusperoni Dec 6, 2026
9768a8a
feat(runtime): enforceImportAttributes app config
edusperoni Dec 6, 2026
e731308
build: pin runtime-common at f73c0f5
edusperoni Dec 6, 2026
e3bad81
build: pin runtime-common at ab7f353
edusperoni Dec 6, 2026
9ae6061
refactor(runtime): host callbacks, import.meta and ns:module from run…
edusperoni Dec 6, 2026
b646096
feat(runtime): appSchemeOrigins app config
edusperoni Dec 6, 2026
80193fe
test: import() of CommonJS and .js files
edusperoni Dec 6, 2026
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
path = test-app/build-tools/android-dts-generator
url = https://github.com/NativeScript/android-dts-generator.git
branch = main
[submodule "test-app/runtime/src/main/cpp/runtime-common"]
path = test-app/runtime/src/main/cpp/runtime-common
url = https://github.com/NativeScript/runtime-common.git
2 changes: 2 additions & 0 deletions test-app/app/src/main/assets/app/esm/json-strict/comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// a comment
{"a": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions test-app/app/src/main/assets/app/esm/json-strict/importer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function load(spec) {
return import(spec, { with: { type: "json" } });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a": 1};globalThis.__jsonStrictInjected = true
1 change: 1 addition & 0 deletions test-app/app/src/main/assets/app/esm/json-strict/ok.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "strict"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"__proto__": {"polluted": true}, "own": 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import data from "./trailing-comma.json" with { type: "json" };
export default data;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a": 1,}
4 changes: 4 additions & 0 deletions test-app/app/src/main/assets/app/mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ require('./tests/testConcurrentProxyGeneration');
require('./tests/testEsmHttpLoader');
// What import() settles with, per importer kind and specifier shape
require('./tests/testDynamicImport');
// JSON modules: strict JSON.parse, and the SyntaxError they reject with
require('./tests/testJsonModules');
// import() of CommonJS files and of .js files with either syntax
require('./tests/testImportCommonJs');
// File modules large enough to load off the JS thread
require('./tests/testFileModuleLoad');
// Node-API addon surface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ exports.run = function () {
// Yield to the looper between benchmarks so GC and queued work run outside timed rounds.
function next() {
if (index >= benchmarks.length) {
runContention();
require("./moduleBenchmarks").run(report, skipped, ROUNDS, SCALE, function (r) {
results.push.apply(results, r);
runContention();
});
return;
}
gc();
Expand Down
21 changes: 21 additions & 0 deletions test-app/app/src/main/assets/app/tests/benchmarks/modbench/hub.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { v0 } from "./m0.mjs";
import { v1 } from "./m1.mjs";
import { v2 } from "./m2.mjs";
import { v3 } from "./m3.mjs";
import { v4 } from "./m4.mjs";
import { v5 } from "./m5.mjs";
import { v6 } from "./m6.mjs";
import { v7 } from "./m7.mjs";
import { v8 } from "./m8.mjs";
import { v9 } from "./m9.mjs";
import { v10 } from "./m10.mjs";
import { v11 } from "./m11.mjs";
import { v12 } from "./m12.mjs";
import { v13 } from "./m13.mjs";
import { v14 } from "./m14.mjs";
import { v15 } from "./m15.mjs";
import { v16 } from "./m16.mjs";
import { v17 } from "./m17.mjs";
import { v18 } from "./m18.mjs";
import { v19 } from "./m19.mjs";
export const sum = v0 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16 + v17 + v18 + v19;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const name = "leaf";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v0 = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v1 = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v10 = 10;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v11 = 11;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v12 = 12;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v13 = 13;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v14 = 14;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v15 = 15;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v16 = 16;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v17 = 17;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v18 = 18;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v19 = 19;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v2 = 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v3 = 3;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v4 = 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v5 = 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v6 = 6;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v7 = 7;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v8 = 8;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v9 = 9;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Module loader rows for the JniBench harness: import() of cached modules
// through each specifier form, and links of a fresh module whose 20 static
// imports are cached. Async, so each row awaits every import.

function rows(appRoot) {
var leafPath = appRoot + "/tests/benchmarks/modbench/leaf.mjs";
var hubSeq = 0;
return [
["module.import() cached relative", 2000, function () { return import("./modbench/leaf.mjs"); }],
["module.import() cached bare mapped", 2000, function () { return import("ns-modbench-leaf"); }],
["module.import() cached app-relative", 2000, function () { return import("~/tests/benchmarks/modbench/leaf.mjs"); }],
["module.import() cached absolute path", 2000, function () { return import(leafPath); }],
["module.import() cached file URL", 2000, function () { return import("file://" + leafPath); }],
["module.import() fresh hub, 20 cached static imports", 200, function () {
return import("./modbench/hub.mjs?i=" + (hubSeq++));
}]
];
}

exports.run = function (report, skipped, rounds, scale, done) {
// The runtime's own spelling of the app root; getFilesDir() may spell it
// through another mount (/data/user/0 for /data/data).
var appRoot = __dirname.slice(0, __dirname.length - "/tests/benchmarks".length);
require("ns:module").configureLoader({ importMap: { imports: { "ns-modbench-leaf": "~/tests/benchmarks/modbench/leaf.mjs" } } });
var list = rows(appRoot).filter(function (row) { return !skipped(row[0]); });
var results = [];
function loop(body, n) {
var i = 0;
return new Promise(function (resolve, reject) {
function step() {
if (i >= n) { resolve(); return; }
i++;
body().then(step, reject);
}
step();
});
}
function runRow(index) {
if (index >= list.length) { done(results); return; }
var row = list[index];
var n = row[1] * scale;
var samples = [];
var r = 0;
loop(row[2], Math.max(200, n >> 2)).then(function round() {
if (r >= rounds) {
results.push(report(row[0], samples, null, n * rounds));
setTimeout(function () { runRow(index + 1); }, 50);
return;
}
r++;
var start = performance.now();
return loop(row[2], n).then(function () {
samples.push(((performance.now() - start) * 1e6) / n);
return round();
});
}).catch(function (e) {
console.log("JNIBENCH_ERROR " + row[0] + ": " + e);
runRow(index + 1);
});
}
runRow(0);
};
144 changes: 144 additions & 0 deletions test-app/app/src/main/assets/app/tests/codeCacheFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// The runtime's on-disk code caches, as the shared core lays them out:
// <code_cache>/v8/<16 hex digits of the FNV-1a 64 hash of the key>, then
// ".mcache" for an ES module or ".cache" for a classic script. The key is the
// source's path relative to the app root, or its absolute path outside it.
// A file is a header (magic "NSCC", version, kind, key length, source size,
// freshness token length, payload length, module format, key, token), then
// V8's payload. The module format is 0 for a classic script, 1 for a CommonJS
// file reached through import (a marker with no payload), 2 for an ES module.
var context = com.tns.NativeScriptApplication.getInstance();
var dir = String(new java.io.File(context.getCodeCacheDir(), "v8").getAbsolutePath());
var appRoot = String(context.getFilesDir().getCanonicalPath()) + "/app";

var FNV_OFFSET = BigInt("0xcbf29ce484222325");
var FNV_PRIME = BigInt("0x100000001b3");
var MASK_64 = (BigInt(1) << BigInt(64)) - BigInt(1);

function fnv1a64(text) {
var bytes = unescape(encodeURIComponent(text));
var hash = FNV_OFFSET;
for (var i = 0; i < bytes.length; i++) {
hash = ((hash ^ BigInt(bytes.charCodeAt(i))) * FNV_PRIME) & MASK_64;
}
var hex = hash.toString(16);
while (hex.length < 16) {
hex = "0" + hex;
}
return hex;
}

function keyFor(path) {
return path.indexOf(appRoot + "/") === 0 ? path.substring(appRoot.length + 1) : path;
}

// `kind` is "module" or "script".
function fileFor(path, kind) {
return dir + "/" + fnv1a64(keyFor(path)) + (kind === "script" ? ".cache" : ".mcache");
}

// What platform::Stat reports as the source's freshness token: its mtime with
// nanoseconds.
function sourceToken(path) {
var mtime = android.system.Os.stat(path).st_mtim;
var nanos = String(mtime.tv_nsec);
while (nanos.length < 9) {
nanos = "0" + nanos;
}
return String(mtime.tv_sec) + "." + nanos;
}

function readBytes(file) {
var f = new java.io.File(file);
return f.exists() ? java.nio.file.Files.readAllBytes(f.toPath()) : null;
}

// The cache file's header, or null when there is no file or it is not a cache.
function readHeader(file) {
var bytes = readBytes(file);
if (bytes === null || bytes.length < 36) {
return null;
}
var u8 = function (i) {
return bytes[i] & 0xff;
};
var u32 = function (i) {
return (u8(i) | (u8(i + 1) << 8) | (u8(i + 2) << 16) | (u8(i + 3) << 24)) >>> 0;
};
var text = function (start, length) {
var out = "";
for (var i = start; i < start + length; i++) {
out += String.fromCharCode(u8(i));
}
return decodeURIComponent(escape(out));
};
if (text(0, 4) !== "NSCC") {
return null;
}
var keyLength = u32(12);
var tokenLength = u32(24);
var payloadStart = 36 + keyLength + tokenLength;
var zeroPayload = true;
for (var i = payloadStart; i < bytes.length && zeroPayload; i++) {
zeroPayload = bytes[i] === 0;
}
return {
version: u32(4),
format: u32(32),
key: text(36, keyLength),
sourceSize: u32(16) + u32(20) * 4294967296,
token: text(36 + keyLength, tokenLength),
payloadStart: payloadStart,
payloadLength: u32(28),
fileLength: bytes.length,
zeroPayload: zeroPayload
};
}

// Whether `file` is a cache for the source at `path` as it is now.
function isFresh(file, path) {
var header = readHeader(file);
return header !== null && header.key === keyFor(path) &&
header.sourceSize === new java.io.File(path).length() &&
header.token === sourceToken(path) &&
header.fileLength === header.payloadStart + header.payloadLength;
}

// Overwrites the payload with zeros and keeps the header, so the cache still
// reads as fresh and V8 rejects it.
function zeroPayload(file) {
var header = readHeader(file);
var bytes = readBytes(file);
for (var i = header.payloadStart; i < bytes.length; i++) {
bytes[i] = 0;
}
var out = new java.io.FileOutputStream(file);
try {
out.write(bytes);
} finally {
out.close();
}
}

// Names in the cache directory that start with `file`'s name and a dot: the
// writer's temporaries.
function temporariesOf(file) {
var name = file.substring(file.lastIndexOf("/") + 1) + ".";
var names = new java.io.File(dir).list();
var found = [];
for (var i = 0; names && i < names.length; i++) {
if (String(names[i]).indexOf(name) === 0) {
found.push(String(names[i]));
}
}
return found;
}

module.exports = {
dir: dir,
fileFor: fileFor,
sourceToken: sourceToken,
readHeader: readHeader,
isFresh: isFresh,
zeroPayload: zeroPayload,
temporariesOf: temporariesOf
};
16 changes: 16 additions & 0 deletions test-app/app/src/main/assets/app/tests/importOnCloseWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Issues an import() of every specifier it is sent, reports "issued", and,
// when told to, closes itself in the same task, so its runtime tears down with
// those imports still loading.
onmessage = function (msg) {
var specs = msg.data.specs;
for (var i = 0; i < specs.length; i++) {
import(specs[i]).catch(function () {});
}
postMessage("issued");
if (msg.data.close) {
close();
for (var j = 0; j < specs.length; j++) {
import(specs[j]).catch(function () {});
}
}
};
24 changes: 24 additions & 0 deletions test-app/app/src/main/assets/app/tests/requireExceptionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,28 @@ describe("Tests require exceptions ", function () {

expect(exceptionCaught).toBe(false);
});

it("throws when a script that exists cannot be read", function () {
var name = "unreadable-" + Date.now() + ".js";
var path = __dirname + "/" + name;
var file = new java.io.File(path);
var writer = new java.io.FileWriter(file);
try {
writer.write("module.exports = { loaded: true };");
} finally {
writer.close();
}
file.setReadable(false, false);
var message;
try {
require(path);
message = "loaded";
} catch (e) {
message = String(e.message || e);
} finally {
file.delete();
}
expect(message).toContain("Cannot read module ");
expect(message).toContain(name);
});
});
Loading