diff --git a/static_core/plugins/ets/doc/runtime/05_imports.rst b/static_core/plugins/ets/doc/runtime/05_imports.rst index 03d65bd3c937bc7de863fc60d3fad20abb216cda..3bfb2a22a5ed37c923392712db9bd8bca1552e82 100644 --- a/static_core/plugins/ets/doc/runtime/05_imports.rst +++ b/static_core/plugins/ets/doc/runtime/05_imports.rst @@ -189,6 +189,10 @@ core runtime side. abcFiles: ABCFile[] // formed from the `paths` list and define the load order } + // platform API + export class MemoryRuntimeLinker extends AbcRuntimeLinker { + constructor(parentLinker: RuntimeLinker | undefined, rawAbcFiles: Array>) + } .. code-block:: typescript :linenos: @@ -211,6 +215,12 @@ core runtime side. /* load an isolated resource */ let isolated = new AbcRuntimeLinker(boot, ["dynamics.abc"]) + /* native function to read binary files */ + native function loadRawFiles() : Array> + + /* load abc file from binary */ + let memLinker = new MemoryRuntimeLinker(boot, loadRawFiles()); + Resolution request from runtime has two inputs: - Runtime class descriptor, which is computed from the **runtime name** used by diff --git a/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml b/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml index e1d8e3f952e6c919d183d16186c913d9c0a71cda..0f9938badcabd0b0848295bb7f2adfa79c8c8865 100644 --- a/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml +++ b/static_core/plugins/ets/runtime/ets_libbase_runtime.yaml @@ -5816,7 +5816,7 @@ intrinsics: - name: StdCoreAbcFileLoadFromMemory space: ets class_name: std.core.AbcFile - method_name: loadFromMemoryImpl + method_name: loadFromMemory static: true signature: ret: std.core.AbcFile diff --git a/static_core/plugins/ets/stdlib/std/core/AbcFile.ets b/static_core/plugins/ets/stdlib/std/core/AbcFile.ets index 15035d346a8625971d50400774e864622676c40e..6e78467b183629de4bb4d77084a59b690a0e2ab6 100644 --- a/static_core/plugins/ets/stdlib/std/core/AbcFile.ets +++ b/static_core/plugins/ets/stdlib/std/core/AbcFile.ets @@ -50,14 +50,7 @@ final class AbcFile { * * @throws errors happened on loading ABC file. */ - public static native loadFromMemoryImpl(runtimeLinker: RuntimeLinker, rawFile: FixedArray): AbcFile; - public static loadFromMemory(runtimeLinker: RuntimeLinker, rawFile: byte[]): AbcFile { - let localFixed: FixedArray = new byte[rawFile.length] - for (let i = 0; i < rawFile.length; i++) { - localFixed[i] = rawFile[i]; - } - return AbcFile.loadFromMemoryImpl(runtimeLinker, localFixed); - } + public static native loadFromMemory(runtimeLinker: RuntimeLinker, rawFile: FixedArray): AbcFile; /** * Loads class from ABC file. @@ -79,4 +72,4 @@ export class AbcFileNotFoundError extends LinkerError { constructor(message?: String, options?: ErrorOptions) { super("AbcFileNotFoundError", message, options) } -} \ No newline at end of file +} diff --git a/static_core/plugins/ets/stdlib/std/core/MemoryRuntimeLinker.ets b/static_core/plugins/ets/stdlib/std/core/MemoryRuntimeLinker.ets index aa15756089ea53c96ed26471860e8f2d02beb86f..674624082c44fde5d48d22cdcc459bc6cf34b01b 100644 --- a/static_core/plugins/ets/stdlib/std/core/MemoryRuntimeLinker.ets +++ b/static_core/plugins/ets/stdlib/std/core/MemoryRuntimeLinker.ets @@ -19,7 +19,7 @@ package std.core; * @class RuntimeLinker backed by in-memory ABC files. */ export class MemoryRuntimeLinker extends AbcRuntimeLinker { - public constructor(parentLinker: RuntimeLinker | undefined, rawAbcFiles: byte[][]) { + public constructor(parentLinker: RuntimeLinker | undefined, rawAbcFiles: Array>) { super(parentLinker, []); const abcFiles : FixedArray = new (AbcFile | undefined)[Double.toInt(rawAbcFiles.length)]; for (let i = 0; i < rawAbcFiles.length; i++) { diff --git a/static_core/plugins/ets/tests/ets_test_suite/linker/runtime_linker_extensions.ets b/static_core/plugins/ets/tests/ets_test_suite/linker/runtime_linker_extensions.ets index 9c41f756f1fff3bf7a505069042f4a4abd49d855..8b9350ccbad085ea09d6d9748cb9967982377b64 100644 --- a/static_core/plugins/ets/tests/ets_test_suite/linker/runtime_linker_extensions.ets +++ b/static_core/plugins/ets/tests/ets_test_suite/linker/runtime_linker_extensions.ets @@ -13,9 +13,6 @@ * limitations under the License. */ -import { launch } from "std/concurrency" -import { Job } from "std/core" - class A { } class DummyRuntimeLinker extends RuntimeLinker { @@ -76,7 +73,7 @@ class Test { Test.testEmptyLinker(linker); } - private static native loadFile(path: string): byte[] | undefined; + private static native loadFile(path: string): FixedArray | undefined; private static getAdditionalFilesList(): string[] { let procManager = new StdProcess.ProcessManager(); @@ -85,8 +82,8 @@ class Test { return abcFiles.split(":"); } - private static loadRawFiles(paths: string[]): byte[][] { - const rawFiles = new byte[paths.length as int][0]; + private static loadRawFiles(paths: string[]): Array> { + const rawFiles = new Array>(paths.length as int); for (let i = 0; i < rawFiles.length; i++) { const raw = Test.loadFile(paths[i]); assertNE(raw, undefined, "failed to load file " + paths[i]); @@ -243,14 +240,14 @@ class Test { Test.testAddAbcFiles(linker, [allAbcFiles[0]]); } - private static addSingleAbcFile(linker: AbcRuntimeLinker, path: string): void { + public static addSingleAbcFile(linker: AbcRuntimeLinker, path: string): void { linker.addAbcFiles([path]); } static testConcurrentAddAbcFiles() { const linker = new AbcRuntimeLinker(undefined, []); const allAbcFiles = Test.getAdditionalFilesList(); - const promises = new Array>(); + const promises = new Array>(); // Add all files except "additional1.ets" for (let i = 1; i < allAbcFiles.length; i++) { promises.push(launch void>(Test.addSingleAbcFile, linker, allAbcFiles[i])); @@ -259,7 +256,7 @@ class Test { expectThrow(() => { linker.loadClass(Test.additionalClass1Name, true); }, (e) => e instanceof LinkerClassNotFoundError ); - promises.forEach((p: Promise): void => { await p; }); + promises.forEach((p: Job): void => { p.Await(); }); Test.addSingleAbcFile(linker, allAbcFiles[0]); // Now class must be found expectNoThrow(() => { linker.loadClass(Test.additionalClass1Name, true); }); @@ -288,6 +285,5 @@ class Test { } function main() { - loadLibrary("runtime_linker_extensions-shared-lib"); Test.test(); }