### Get Available Modules Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/getAvailableModules.html Use this snippet to retrieve and print a list of all modules available to the engine. Ensure the engine is initialized before calling this method. ```dart final modules = await engine.getAvailableModules(); print(modules); ``` -------------------------------- ### JsModule Example Usage Source: https://pub.dev/documentation/fjs/latest/fjs/JsModule-class.html Illustrative examples of how to create and use JsModule instances. ```APIDOC ## Example Usage ```dart // Create a module from inline code final module = JsModule.code( module: 'my-utils', code: 'export const add = (a, b) => a + b;', ); // Create a module from a file final module2 = JsModule.path( module: 'math', path: '/path/to/math.js', ); // Create a module from bytes final module3 = JsModule.bytes( module: 'binary-utils', bytes: utf8.encode('export const VERSION = "1.0";'), ); ``` ``` -------------------------------- ### mapOrNull Implementation Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsBuiltinOptionsPatterns/mapOrNull.html An example demonstrating the implementation of the mapOrNull method, showing how it handles specific cases and falls back to null. ```dart @optionalTypeArgs TResult? mapOrNull( TResult? Function(_JsBuiltinOptions value)? $default, ) { final _that = this; switch (_that) { case _JsBuiltinOptions() when $default != null: return $default(_that); case _: return null; } } ``` -------------------------------- ### whenOrNull Implementation Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsModuleBytecodeOptionsPatterns/whenOrNull.html An example demonstrating the implementation of the whenOrNull method, showing how it handles specific cases and falls back to null. ```dart @optionalTypeArgs TResult? whenOrNull( TResult? Function(JsBytecodeEndianness? endianness, bool? stripSource, bool? stripDebug)? $default, ) { final _that = this; switch (_that) { case _JsModuleBytecodeOptions() when $default != null: return $default(_that.endianness, _that.stripSource, _that.stripDebug); case _: return null; } } ``` -------------------------------- ### Get Declared Modules Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/getDeclaredModules.html Demonstrates how to call the getDeclaredModules method and print the resulting list of module names. Ensure the engine is initialized and module storage is available. ```dart final modules = await engine.getDeclaredModules(); print('Declared modules: $modules'); ``` -------------------------------- ### Get mallocSize Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/mallocSize.html Use this to retrieve the size of allocated memory. No setup is required. ```javascript PlatformInt64 get mallocSize; ``` -------------------------------- ### JsEvalOptions Constructors and Usage Source: https://pub.dev/documentation/fjs/latest/fjs/JsEvalOptions-class.html Demonstrates how to create instances of JsEvalOptions using default settings, with promise support, or with custom configurations. ```APIDOC ## JsEvalOptions Constructors and Usage ### Description This section shows how to instantiate the `JsEvalOptions` class with different configurations. ### Constructors `JsEvalOptions({bool? global, bool? strict, bool? backtraceBarrier, bool? promise})` Creates new evaluation options with the specified parameters. `JsEvalOptions.raw({bool? global, bool? strict, bool? backtraceBarrier, bool? promise})` ### Static Methods `JsEvalOptions.defaults()` Creates options with default values (global scope, strict mode). `JsEvalOptions.withPromise()` Creates options with promise support enabled. `JsEvalOptions.module()` Creates options for module evaluation. ### Example Usage ```dart // Default options final opts1 = JsEvalOptions.defaults(); // With promise support final opts2 = JsEvalOptions.withPromise(); // Custom options final opts3 = JsEvalOptions( global: true, strict: true, backtraceBarrier: false, promise: true, ); ``` ``` -------------------------------- ### Get isOk Property Source: https://pub.dev/documentation/fjs/latest/fjs/JsResult/isOk.html Returns true if the JsResult is an Ok type. No setup is required. ```dart bool get isOk => this is JsResult_Ok; ``` -------------------------------- ### Get JsBytecode Endianness Source: https://pub.dev/documentation/fjs/latest/fjs/JsModuleBytecodeOptions/endianness.html Use this to retrieve the endianness of JsBytecode. No specific setup is required. ```javascript JsBytecodeEndianness? get endianness; ``` -------------------------------- ### Get cFuncCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/cFuncCount.html Use this to retrieve the count of functions. No specific setup is required beyond having access to the PlatformInt64 type. ```csharp PlatformInt64 get cFuncCount; ``` -------------------------------- ### JsEngineRuntimeOptions Class Overview Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngineRuntimeOptions-class.html This snippet provides an overview of the JsEngineRuntimeOptions class, including its constructor, properties, and available methods. ```APIDOC ## JsEngineRuntimeOptions Class Runtime configuration applied when constructing a high-level `JsEngine`. ### Available extensions * JsEngineRuntimeOptionsPatterns ### Annotations * @freezed ## Constructors ### JsEngineRuntimeOptions ```dart JsEngineRuntimeOptions({BigInt? memoryLimit, BigInt? gcThreshold, BigInt? maxStackSize, String? info}) ``` ## Properties ### copyWith ```dart copyWith → $JsEngineRuntimeOptionsCopyWith ``` Create a copy of JsEngineRuntimeOptions with the given fields replaced by the non-null parameter values. ### gcThreshold ```dart gcThreshold → BigInt? ``` ### hashCode ```dart hashCode → int ``` The hash code for this object. ### info ```dart info → String? ``` ### maxStackSize ```dart maxStackSize → BigInt? ``` ### memoryLimit ```dart memoryLimit → BigInt? ``` ### runtimeType ```dart runtimeType → Type ``` A representation of the runtime type of the object. ## Methods ### map ```dart map(TResult Function(_JsEngineRuntimeOptions value) default) ``` Available on JsEngineRuntimeOptions, provided by the JsEngineRuntimeOptionsPatterns extension A `switch`-like method, using callbacks. ### mapOrNull ```dart mapOrNull(TResult? Function(_JsEngineRuntimeOptions value)? default) ``` Available on JsEngineRuntimeOptions, provided by the JsEngineRuntimeOptionsPatterns extension A variant of `map` that fallback to returning `null`. ### maybeMap ```dart maybeMap(TResult Function(_JsEngineRuntimeOptions value) default, {required TResult Function() orElse}) ``` Available on JsEngineRuntimeOptions, provided by the JsEngineRuntimeOptionsPatterns extension A variant of `map` that fallback to returning `orElse`. ### maybeWhen ```dart maybeWhen(TResult Function(BigInt? memoryLimit, BigInt? gcThreshold, BigInt? maxStackSize, String? info)? default, {required TResult Function() orElse}) ``` Available on JsEngineRuntimeOptions, provided by the JsEngineRuntimeOptionsPatterns extension A variant of `when` that fallback to an `orElse` callback. ### noSuchMethod ```dart noSuchMethod(Invocation invocation) ``` Invoked when a nonexistent method or property is accessed. ### toString ```dart tosString() → String ``` A string representation of this object. ### when ```dart when(TResult Function(BigInt? memoryLimit, BigInt? gcThreshold, BigInt? maxStackSize, String? info) default) ``` Available on JsEngineRuntimeOptions, provided by the JsEngineRuntimeOptionsPatterns extension A `switch`-like method, using callbacks. ### whenOrNull ```dart whenOrNull(TResult? Function(BigInt? memoryLimit, BigInt? gcThreshold, BigInt? maxStackSize, String? info)? default) ``` Available on JsEngineRuntimeOptions, provided by the JsEngineRuntimeOptionsPatterns extension A variant of `when` that fallback to returning `null`. ## Operators ### operator == ```dart operator ==(Object other) → bool ``` The equality operator. ## Static Methods ### default_ ```dart default_() → Future ``` ``` -------------------------------- ### Get Field0 Property Source: https://pub.dev/documentation/fjs/latest/fjs/JsCode/field0.html Use this to retrieve the value of the inherited field0 property. No specific setup is required beyond having an object instance. ```Object Object get field0; ``` -------------------------------- ### Configure JsBuiltinOptions Source: https://pub.dev/documentation/fjs/latest/fjs/JsBuiltinOptions-class.html Demonstrates various ways to instantiate JsBuiltinOptions. Use '.all()' to enable all builtins, '.essential()' for core modules, '.web()' for a web-like environment, or provide a custom configuration. ```dart // Enable all builtins final opts1 = JsBuiltinOptions.all(); // Enable only essential modules final opts2 = JsBuiltinOptions.essential(); // Web-like environment final opts3 = JsBuiltinOptions.web(); // Custom configuration final opts4 = JsBuiltinOptions( console: true, timers: true, fetch: true, ); ``` -------------------------------- ### Compile Script with Default Options Source: https://pub.dev/documentation/fjs/latest/fjs/JsScriptBytecodeOptions/defaults.html Use `JsScriptBytecodeOptions.defaults()` to get default options and `copyWith` to modify them. This example compiles a script that resolves a promise. ```dart final options = JsScriptBytecodeOptions.defaults().copyWith( promise: true, ); final script = await JsBytecode.compileScript( name: 'bootstrap.js', source: JsCode.code('await Promise.resolve("ready")'), options: options, ); ``` -------------------------------- ### Declare New Bytecode Module Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/declareNewBytecodeModule.html Use this snippet to declare a new bytecode-backed module. The bytecode must be compiled for the same QuickJS version as FJS and should only come from trusted sources. Once declared, the module can be imported. ```dart final bytecode = await JsBytecode.compile( module: JsModule.code( module: 'feature/config', code: 'export const version = "2.2.0";', ), ); await engine.declareNewBytecodeModule(module: bytecode); ``` -------------------------------- ### Get jsFuncSize Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/jsFuncSize.html Use this property to retrieve the size of a JavaScript function. No specific setup or imports are required beyond the PlatformInt64 type. ```dart PlatformInt64 get jsFuncSize; ``` -------------------------------- ### Quick Start: Initialize Engine and Evaluate JavaScript Source: https://pub.dev/documentation/fjs/latest/index.html Initialize the FJS engine with built-in modules and execute a simple JavaScript expression. Ensure LibFjs.init() is called before creating an engine. ```dart import 'package:fjs/fjs.dart'; void main() async { await LibFjs.init(); // Create engine with builtin modules final engine = await JsEngine.create( builtins: JsBuiltinOptions( console: true, fetch: true, timers: true, ), ); await engine.init(bridge: (jsValue) { return JsResult.ok(JsValue.string('Hello from Dart')); }); // Execute JavaScript final result = await engine.eval(source: JsCode.code(''' console.log('Hello from FJS!'); 1 + 2 ''')); print(result.value); // 3 await engine.close(); } ``` -------------------------------- ### Get fastArrayElements Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/fastArrayElements.html This snippet shows how to access the fastArrayElements property of a PlatformInt64 object. No specific setup is required beyond having an instance of PlatformInt64. ```csharp PlatformInt64 get fastArrayElements; ``` -------------------------------- ### JsEvalOptions Defaults and Customization Source: https://pub.dev/documentation/fjs/latest/fjs/JsEvalOptions-class.html Demonstrates creating JsEvalOptions with default settings, promise support, and custom configurations. ```dart // Default options final opts1 = JsEvalOptions.defaults(); // With promise support final opts2 = JsEvalOptions.withPromise(); // Custom options final opts3 = JsEvalOptions( global: true, strict: true, backtraceBarrier: false, promise: true, ); ``` -------------------------------- ### Get binaryObjectCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/binaryObjectCount.html Use this property to retrieve the count of binary objects. No specific setup or imports are required beyond the platform's standard environment. ```cpp PlatformInt64 get binaryObjectCount; ``` -------------------------------- ### JsEngine Constructors Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine-class.html Information about how to create instances of the JsEngine class. ```APIDOC ## JsEngine() ### Description Creates a new JsEngine instance. ### Method Constructor ### Endpoint N/A ``` -------------------------------- ### Compile and Register JavaScript Bytecode Modules Source: https://pub.dev/documentation/fjs/latest/index.html Compile ES modules into QuickJS bytecode, validate the bytecode, register it with the engine, and then import and execute it. Also shows how to reconstruct bytecode from persisted bytes. ```dart // Compile an ES module into QuickJS bytecode without touching the current engine. final bytecode = await JsBytecode.compile( module: JsModule.code( module: 'plugin/main.js', code: 'export function run() { return "ready"; }', ), options: JsModuleBytecodeOptions.defaults(), ); // Validate the bytecode payload before declaring it. await JsBytecode.validate(module: bytecode); // Register the precompiled module on the engine. await engine.declareNewBytecodeModule(module: bytecode); // Import and execute the declared module like any other ES module. final result = await engine.eval(source: JsCode.code(''' const { run } = await import('plugin/main.js'); run(); ''')); // Reconstruct bytecode from persisted bytes when loading from storage. final restored = JsModuleBytecode( name: bytecode.name, bytes: bytecode.bytes, ); JsBytecode.validateSync(module: restored); ``` -------------------------------- ### Get Engine Memory Usage Statistics Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/memoryUsage.html Call this method to retrieve memory usage statistics for the engine-owned runtime. No specific setup is required beyond having access to the engine. ```java Future memoryUsage(); ``` -------------------------------- ### Evaluate Bytecode Bundle Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/evaluateBytecodeBundle.html Evaluates a bytecode bundle and then imports and accesses a property from the default export of the entry module. Ensure the bundle is correctly prepared and the entry module is specified. ```dart await engine.evaluateBytecodeBundle(bundle: pluginBundle); final result = await engine.eval(source: JsCode.code(''' const { default: plugin } = await import('plugins/main'); plugin.name ''')); ``` -------------------------------- ### Get propSize Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/propSize.html This snippet shows how to get the propSize property, which returns a PlatformInt64. ```csharp PlatformInt64 get propSize; ``` -------------------------------- ### executeRustInitializers Method Source: https://pub.dev/documentation/fjs/latest/fjs/LibFjs/executeRustInitializers.html This method is automatically generated and should not be called directly by developers. It handles the initialization of Rust crates. ```APIDOC ## executeRustInitializers Method ### Description This method is intended for use by automatically generated code only and should not be invoked directly by developers. It ensures that Rust crates are properly initialized. ### Method Future ### Endpoint N/A (Internal method) ### Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (void) This method does not return any value. #### Response Example None ``` -------------------------------- ### Get backtraceBarrier Property Source: https://pub.dev/documentation/fjs/latest/fjs/JsEvalOptions/backtraceBarrier.html This snippet shows how to get the value of the backtraceBarrier property. It is a nullable boolean. ```dart bool? get backtraceBarrier; ``` -------------------------------- ### JsEngineRuntimeOptions Source: https://pub.dev/documentation/fjs/latest/index.html Options for configuring the JavaScript engine runtime. ```APIDOC ## JsEngineRuntimeOptions Options for configuring the JavaScript engine runtime. ```dart sealed class JsEngineRuntimeOptions { const factory JsEngineRuntimeOptions({ BigInt? memoryLimit, BigInt? gcThreshold, BigInt? maxStackSize, String? info, }); } ``` ``` -------------------------------- ### Get Strict Property Implementation Source: https://pub.dev/documentation/fjs/latest/fjs/JsEvalOptions/strict.html This snippet shows the declaration for getting the strict property. It is a nullable boolean. ```dart bool? get strict; ``` -------------------------------- ### JsEngineRuntimeOptions Default Static Method Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngineRuntimeOptions/default_.html Provides the default static method to obtain JsEngineRuntimeOptions. ```APIDOC ## static method default_ ### Description Returns the default JsEngineRuntimeOptions. ### Method static ### Endpoint N/A ### Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **JsEngineRuntimeOptions** (Future) - The default runtime options. ### Response Example ```dart Future default_() ``` ``` -------------------------------- ### Validate Bundle Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsBytecode/validateBundle.html Example usage of the validateBundle static method. Ensure a compiled bundle is available before calling. ```dart await JsBytecode.validateBundle(bundle: compiledBundle); ``` -------------------------------- ### JsModule Constructors Source: https://pub.dev/documentation/fjs/latest/fjs/JsModule-class.html This section details the different ways to construct a JsModule instance. ```APIDOC ## JsModule Constructors ### JsModule.code Creates a module from inline source text. **Parameters** - **module** (String) - Required - The name of the module. - **code** (String) - Required - The JavaScript source code as a string. ### JsModule.path Creates a module from a file path. **Parameters** - **module** (String) - Required - The name of the module. - **path** (String) - Required - The path to the JavaScript file. ### JsModule.bytes Creates a module from raw UTF-8 source bytes. **Parameters** - **module** (String) - Required - The name of the module. - **bytes** (List) - Required - The UTF-8 encoded source bytes. ``` -------------------------------- ### Load JavaScript Code and Modules Source: https://pub.dev/documentation/fjs/latest/index.html Demonstrates loading JavaScript code and modules from inline strings, file paths, or byte arrays. Also shows how to configure evaluation options for scripts and modules. ```dart import 'dart:convert'; import 'dart:typed_data'; // Source code can come from a string, a file path, or UTF-8 bytes. final inlineCode = JsCode.code('1 + 1'); final fileCode = JsCode.path('/absolute/path/to/script.js'); final bytesCode = JsCode.bytes(Uint8List.fromList(utf8.encode('2 + 2'))); // Modules support the same three source forms. final inlineModule = JsModule.code( module: 'feature/inline', code: 'export const enabled = true;', ); final fileModule = JsModule.path( module: 'feature/file', path: '/absolute/path/to/feature.js', ); final bytesModule = JsModule.bytes( module: 'feature/bytes', bytes: utf8.encode('export const answer = 42;'), ); // Eval options control whether code runs as global script, async code, or module-style code. final defaultEval = JsEvalOptions.defaults(); final asyncEval = JsEvalOptions.withPromise(); final moduleEval = JsEvalOptions.module(); ``` -------------------------------- ### Get jsFuncPc2LineSize Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/jsFuncPc2LineSize.html This code snippet shows how to get the jsFuncPc2LineSize property. It is a read-only property of type PlatformInt64. ```csharp PlatformInt64 get jsFuncPc2LineSize; ``` -------------------------------- ### initMockImpl Method Source: https://pub.dev/documentation/fjs/latest/fjs/LibFjs/initMockImpl.html Initializes the mock implementation of the API. This method is protected and intended for use by generated code only, not for direct developer invocation. ```APIDOC ## initMockImpl Method ### Description Initializes the mock implementation of the API. This method is protected and intended for use by generated code only, not for direct developer invocation. ### Method `void` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **api** (LibFjsApi) - Required - The API implementation to be used for mocking. ### Request Example ```json { "api": "" } ``` ### Response #### Success Response (200) This method does not return a value upon successful execution. #### Response Example None ### Error Handling - Throws `StateError` if the flutter_rust_bridge has already been initialized. ``` -------------------------------- ### Get Strict Property Implementation Source: https://pub.dev/documentation/fjs/latest/fjs/JsScriptBytecodeOptions/strict.html This snippet shows the Dart implementation for getting the strict property. It is a nullable boolean. ```dart bool? get strict; ``` -------------------------------- ### Implement setInfo Abstract Method Source: https://pub.dev/documentation/fjs/latest/fjs/JsRuntime/setInfo.html This is the abstract method signature for setting runtime info. It requires a String parameter named 'info'. ```dart void setInfo({required String info}); ``` -------------------------------- ### Get stripDebug Property Implementation Source: https://pub.dev/documentation/fjs/latest/fjs/JsModuleBytecodeOptions/stripDebug.html This snippet shows the implementation of the get stripDebug property. It is inherited and returns a nullable boolean. ```dart bool? get stripDebug; ``` -------------------------------- ### JsContext Constructors Source: https://pub.dev/documentation/fjs/latest/fjs/JsContext-class.html Information about how to create a JsContext instance. ```APIDOC ## JsContext() ### Description Creates a new JsContext instance. ### Method Constructor ### Endpoint N/A ### Parameters None ### Request Example ```dart var context = JsContext(); ``` ### Response N/A ``` ```APIDOC ## JsContext.from({required JsRuntime runtime}) ### Description Creates a new context from a given JsRuntime. ### Method Static Method ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```dart var runtime = JsRuntime(); // Assuming JsRuntime is defined elsewhere var context = JsContext.from(runtime: runtime); ``` ### Response N/A ``` -------------------------------- ### Create JsModuleBytecodeBundle Source: https://pub.dev/documentation/fjs/latest/fjs/JsModuleBytecodeBundle/JsModuleBytecodeBundle.html Use this constructor to create a bundle of bytecode modules. Set `entry` when the bundle will later be executed with `engine.evaluateBytecodeBundle(...)`. Leave it `null` when the bundle is only used for declaration. ```dart final bundle = JsModuleBytecodeBundle( entry: 'feature/index', modules: [ featureIndexBytecode, sharedUtilBytecode, ], ); ``` -------------------------------- ### Execute Rust Initializers Source: https://pub.dev/documentation/fjs/latest/fjs/LibFjs/executeRustInitializers.html This method is intended for use by automatically generated code only. It initializes the crate API. ```dart @override Future executeRustInitializers() async { await api.crateApiInitApp(); } ``` -------------------------------- ### whenOrNull Fallback Example Source: https://pub.dev/documentation/fjs/latest/fjs/JsBuiltinOptionsPatterns/whenOrNull.html This example demonstrates the fallback behavior of whenOrNull. If the sealed class does not match any specific case (e.g., it's not a Subclass), it returns null, preventing errors. ```dart switch (sealedClass) { case Subclass(:final field): return ...; case _: return null; } ``` -------------------------------- ### Get Runtime Memory Summary Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/summary.html Call the summary() method on the memory usage object to get a formatted string of memory statistics. This is useful for monitoring and debugging memory consumption. ```dart final memory = await runtime.memoryUsage(); print(memory.summary()); // Output: Memory: 123456 bytes, Objects: 42, Functions: 10, Strings: 25 ``` -------------------------------- ### POST /evaluateBytecodeBundle Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/evaluateBytecodeBundle.html Declares a bytecode bundle and evaluates its entry module. The bundle entry must be present in `bundle.modules`. The return value is the module evaluation completion value, so import the entry afterwards if you need exported data. ```APIDOC ## POST /evaluateBytecodeBundle ### Description Declares a bytecode bundle and evaluates its entry module. The bundle entry must be present in `bundle.modules`. The return value is the module evaluation completion value, so import the entry afterwards if you need exported data. ### Method POST ### Endpoint /evaluateBytecodeBundle ### Parameters #### Request Body - **bundle** (JsModuleBytecodeBundle) - Required - The bytecode bundle to evaluate. ### Request Example ```json { "bundle": { ... } } ``` ### Response #### Success Response (200) - **JsValue** - The module evaluation completion value. #### Response Example ```json { "result": "some_value" } ``` ``` -------------------------------- ### Example Implementation of operator == Source: https://pub.dev/documentation/fjs/latest/fjs/JsModuleBytecodeBundle/operator_equals.html An example implementation of the `operator ==` method for the `JsModuleBytecodeBundle` class, showcasing how to handle object identity, type checking, and deep equality comparison for properties. ```APIDOC ## @override bool operator ==(Object other) ### Description This is an example implementation of the equality operator (`==`) for a class, likely `JsModuleBytecodeBundle`. It checks for object identity first, then verifies that the `other` object is of the same runtime type. It proceeds to compare specific properties like `entry` and `modules` using `DeepCollectionEquality` for the latter. ### Method `operator ==` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **bool** - Returns `true` if the objects are considered equal based on the defined logic, `false` otherwise. #### Response Example ```dart @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is JsModuleBytecodeBundle && (identical(other.entry, entry) || other.entry == entry) && const DeepCollectionEquality().equals(other.modules, modules)); } ``` ``` -------------------------------- ### JsModule.bytes Source: https://pub.dev/documentation/fjs/latest/fjs/JsModule/bytes.html Creates a module from raw UTF-8 source bytes. The bytes should be JavaScript source text, not QuickJS bytecode. ```APIDOC ## POST /api/modules/bytes ### Description Creates a JavaScript module from raw UTF-8 source bytes. This method is suitable for providing JavaScript source code directly. ### Method POST ### Endpoint /api/modules/bytes ### Parameters #### Request Body - **module** (String) - Required - The name or identifier for the module. - **bytes** (List) - Required - A list of integers representing the UTF-8 encoded JavaScript source code. ### Request Example ```json { "module": "embedded/config", "bytes": [101, 120, 112, 111, 114, 116, 32, 99, 111, 110, 115, 116, 32, 101, 110, 118, 32, 61, 32, "\"prod\""] } ``` ### Response #### Success Response (200) - **JsModule** (Object) - An object representing the created JavaScript module. #### Response Example ```json { "module": "embedded/config", "source": "export const env = \"prod\";" } ``` ``` -------------------------------- ### Get Default JsBytecodeEndianness Source: https://pub.dev/documentation/fjs/latest/fjs/JsBytecodeEndianness/default_.html Retrieves the default JsBytecodeEndianness value. ```APIDOC ## GET /websites/pub_dev_fjs/default_static_method ### Description Retrieves the default JsBytecodeEndianness value. ### Method GET ### Endpoint /websites/pub_dev_fjs/default_static_method ### Parameters ### Request Body ### Request Example ### Response #### Success Response (200) - **endianness** (JsBytecodeEndianness) - The default endianness value. #### Response Example { "endianness": "little" } ``` -------------------------------- ### Get ObjCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/objCount.html Retrieves the objCount property. This is a PlatformInt64 type. ```C++ PlatformInt64 get objCount; ``` -------------------------------- ### Implementation Details Source: https://pub.dev/documentation/fjs/latest/fjs/JsEvalOptionsPatterns/whenOrNull.html This section provides the implementation details of the whenOrNull method, illustrating how it handles different cases and returns values. ```APIDOC ## Implementation ```dart @optionalTypeArgs TResult? whenOrNull({ TResult? Function(bool? global, bool? strict, bool? backtraceBarrier, bool? promise)? raw, }) { final _that = this; switch (_that) { case _JsEvalOptions() when raw != null: return raw(_that.global, _that.strict, _that.backtraceBarrier, _that.promise); case _: return null; } } ``` ### Explanation - The method uses a `switch` statement to check the type of `_that` (the current instance). - If `_that` is an instance of `_JsEvalOptions` and the `raw` function is provided (not null), the `raw` function is called with the corresponding properties (`global`, `strict`, `backtraceBarrier`, `promise`) from `_that`, and its return value is returned. - For any other case (`_`), the method returns `null`. ``` -------------------------------- ### Create a new JsModule instance Source: https://pub.dev/documentation/fjs/latest/fjs/JsModule/JsModule.html Use this constructor to create a new module with a given name and source code. Ensure the source code is provided as a JsCode object. ```dart final module = JsModule( name: 'math', source: JsCode.code('export const add = (a, b) => a + b;'), ); ``` -------------------------------- ### Get Binary Object Count Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/binaryObjectCount.html Retrieves the count of binary objects. ```APIDOC ## GET /websites/pub_dev_fjs/binaryObjectCount ### Description Retrieves the count of binary objects. ### Method GET ### Endpoint /websites/pub_dev_fjs/binaryObjectCount ### Response #### Success Response (200) - **binaryObjectCount** (PlatformInt64) - The count of binary objects. ``` -------------------------------- ### Get Global Property Source: https://pub.dev/documentation/fjs/latest/fjs/JsEvalOptions/global.html Retrieves the current value of the global property. ```APIDOC ## GET /global ### Description Retrieves the current value of the global property. ### Method GET ### Endpoint /global ### Parameters #### Query Parameters - **inherited** (boolean) - Optional - Specifies whether to retrieve the inherited value. ### Response #### Success Response (200) - **global** (boolean?) - The current value of the global property. ### Response Example ```json { "global": true } ``` ``` -------------------------------- ### compileScript static method Source: https://pub.dev/documentation/fjs/latest/fjs/JsBytecode/compileScript.html Compiles a classic global script into QuickJS bytecode. Set `options.promise` to `true` when the script should support top-level `await`. ```APIDOC ## compileScript static method ### Description Compiles a classic global script into QuickJS bytecode. Set `options.promise` to `true` when the script should support top-level `await`. ### Method POST ### Endpoint /websites/pub_dev_fjs/compileScript ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **name** (String) - Required - The name of the script. - **source** (JsCode) - Required - The JavaScript code to compile. - **options** (JsScriptBytecodeOptions) - Optional - Options for bytecode compilation. ### Request Example ```json { "name": "bootstrap.js", "source": "await Promise.resolve(globalThis.ready = true)", "options": { "promise": true } } ``` ### Response #### Success Response (200) - **bytecode** (JsScriptBytecode) - The compiled QuickJS bytecode. #### Response Example ```json { "bytecode": "..." } ``` ``` -------------------------------- ### Basic JavaScript Execution in Flutter Source: https://pub.dev/documentation/fjs/latest/fjs Demonstrates how to create, initialize, and evaluate simple JavaScript code using the FJS engine. Ensure the engine is created with appropriate built-ins and initialized before execution. ```dart import 'package:fjs/fjs.dart'; // Create an engine final engine = await JsEngine.create( builtins: JsBuiltinOptions.all(), ); // Initialize the engine await engine.initWithoutBridge(); // Execute JavaScript code final result = await engine.eval( source: JsCode.code('Math.random() * 100'), ); print('Random number: ${result.value}'); ``` -------------------------------- ### Get Temporal Property Source: https://pub.dev/documentation/fjs/latest/fjs/JsBuiltinOptions/temporal.html Retrieves the current value of the temporal property. ```APIDOC ## GET /websites/pub_dev_fjs/temporal_property ### Description Retrieves the boolean value indicating if the temporal property is enabled. ### Method GET ### Endpoint /websites/pub_dev_fjs/temporal_property ### Parameters None ### Request Example None ### Response #### Success Response (200) - **temporal** (bool?) - The current state of the temporal property. Can be true, false, or null if not set. #### Response Example ```json { "temporal": true } ``` ``` -------------------------------- ### Compile JavaScript module with default options Source: https://pub.dev/documentation/fjs/latest/fjs/JsModuleBytecodeOptions/defaults.html Example of compiling a JavaScript module using the default `JsModuleBytecodeOptions`. This demonstrates how to create bytecode suitable for distribution. ```dart final options = JsModuleBytecodeOptions.defaults(); final bytecode = await JsBytecode.compile( module: JsModule.code( module: 'feature/main', code: 'export default 42;', ), options: options, ); ``` -------------------------------- ### GET /totalAllocations Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/totalAllocations.html Retrieves the total allocation count performed by the JavaScript runtime. ```APIDOC ## GET /totalAllocations ### Description Returns the total allocation count performed by the JavaScript runtime. This represents the total number of memory allocations. ### Method GET ### Endpoint /totalAllocations ### Returns #### Success Response (200) - **totalAllocations** (PlatformInt64) - Total number of allocations ``` -------------------------------- ### Initialization API Source: https://pub.dev/documentation/fjs/latest/fjs/LibFjs/init.html Provides details on how to initialize the flutter_rust_bridge using the static init method. ```APIDOC ## static init ### Description Initializes flutter_rust_bridge with optional API, handler, and external library configurations. ### Method static Future ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **api** (LibFjsApi?) - Optional - An instance of LibFjsApi. - **handler** (BaseHandler?) - Optional - An instance of BaseHandler. - **externalLibrary** (ExternalLibrary?) - Optional - An instance of ExternalLibrary. - **forceSameCodegenVersion** (bool) - Optional - Defaults to true. Forces the same codegen version. ### Request Example ```dart await YourClass.init( api: yourApiInstance, handler: yourHandlerInstance, externalLibrary: yourExternalLibraryInstance, forceSameCodegenVersion: false, ); ``` ### Response #### Success Response (200) void #### Response Example None (This method returns void upon successful initialization). ``` -------------------------------- ### Get shapeCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/shapeCount.html Retrieves the count of shapes. This property returns a PlatformInt64. ```csharp PlatformInt64 get shapeCount; ``` -------------------------------- ### Get Memory Used Size Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/memoryUsedSize.html Retrieves the current memory usage size. ```APIDOC ## GET /memoryUsedSize ### Description Retrieves the current memory usage size of the platform. ### Method GET ### Endpoint /memoryUsedSize ### Parameters None ### Request Example None ### Response #### Success Response (200) - **memoryUsedSize** (PlatformInt64) - The amount of memory currently in use. ``` -------------------------------- ### JsRuntime Constructors Source: https://pub.dev/documentation/fjs/latest/fjs/JsRuntime-class.html Information about how to create new JsRuntime instances. ```APIDOC ## JsRuntime() ### Description Creates a new JavaScript runtime with default configuration. ### Method Constructor ### Endpoint N/A ### Parameters None ### Request Example ```dart var runtime = JsRuntime(); ``` ### Response #### Success Response (200) - **JsRuntime** - A new JavaScript runtime instance. #### Response Example ```dart // JsRuntime instance ``` ``` ```APIDOC ## JsRuntime.create() ### Description Creates a new JavaScript runtime with custom builtin modules. ### Method Factory ### Endpoint N/A ### Parameters #### Query Parameters - **builtins** (JsBuiltinOptions?) - Optional - Custom builtin modules to include. - **modules** (List?) - Optional - A list of modules to load. ### Request Example ```dart var runtime = await JsRuntime.create(modules: myModules); ``` ### Response #### Success Response (200) - **Future** - A future that resolves to a new JavaScript runtime instance. #### Response Example ```dart // JsRuntime instance ``` ``` -------------------------------- ### Get strCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/strCount.html This property returns the count of strings. It is of type PlatformInt64. ```csharp PlatformInt64 get strCount; ``` -------------------------------- ### JsEngine Methods Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine-class.html Documentation for the methods available on the JsEngine class. ```APIDOC ## Methods ### `call({required String module, required String method, List? params}) → Future` Calls a function in a module. ### `clearPendingModules() → Future` Clears dynamic modules that have not been loaded into the QuickJS module cache. ### `close() → Future` Closes the engine and releases resources. ### `declareNewBytecodeBundle({required JsModuleBytecodeBundle bundle}) → Future` Declares a bundle of bytecode-backed modules without executing them. ### `declareNewBytecodeModule({required JsModuleBytecode module}) → Future` Declares a new bytecode-backed module without executing it. ### `declareNewBytecodeModules({required List modules}) → Future` Declares multiple bytecode-backed modules without executing them. ### `declareNewModule({required JsModule module}) → Future` Declares a new module without executing it. ### `declareNewModules({required List modules}) → Future` Declares multiple new modules without executing them. ### `dispose() → void` Dispose the underlying `Arc`. ### `eval({required JsCode source, JsEvalOptions? options}) → Future` Evaluates JavaScript code and returns the result. ### `evaluateBytecodeBundle({required JsModuleBytecodeBundle bundle}) → Future` Declares a bytecode bundle and evaluates its entry module. ### `evaluateBytecodeModule({required JsModuleBytecode module}) → Future` Evaluates a bytecode-backed module (registers and executes it). ### `evaluateModule({required JsModule module}) → Future` Evaluates a module (registers and executes it). ### `evaluateScriptBytecode({required JsScriptBytecode script}) → Future` Evaluates classic script bytecode in the current global context. ### `executePendingJob() → Future` Advances the engine-owned runtime by one scheduler step. ### `getAvailableModules() → Future>` Gets all modules available to this engine. ### `getDeclaredModules() → Future>` Gets all declared module names. ### `idle() → Future` Runs the engine-owned runtime until quiescent. ### `init({required FutureOr bridge(JsValue)}) → Future` Initializes the engine with a bridge callback for Dart-JS communication. ### `initWithoutBridge() → Future` Initializes the engine without a bridge callback. ### `isJobPending() → Future` Returns whether the engine-owned runtime still has work pending. ### `isModuleAvailable({required String moduleName}) → Future` Checks if a module is available to the engine. ### `isModuleDeclared({required String moduleName}) → Future` Checks if a module is declared. ### `memoryUsage() → Future` Returns memory usage statistics for the engine-owned runtime. ### `noSuchMethod(Invocation invocation) → dynamic` Invoked when a nonexistent method or property is accessed. ### `runGc() → Future` Forces a garbage collection pass on the engine-owned runtime. ### `setGcThreshold({required BigInt threshold}) → Future` Sets the garbage collection threshold on the engine-owned runtime. ### `setInfo({required String info}) → Future` Sets runtime metadata on the engine-owned runtime. ### `setMaxStackSize({required BigInt limit}) → Future` Sets the max stack size on the engine-owned runtime. ### `setMemoryLimit({required BigInt limit}) → Future` Sets the memory limit on the engine-owned runtime. ``` -------------------------------- ### Loading and Executing JavaScript Modules Source: https://pub.dev/documentation/fjs/latest/fjs Shows how to load a JavaScript module from a file path and then execute a function exported by that module. This requires declaring the module with its path before attempting to import and use its functions. ```dart // Load a module from file await engine.declareNewModule( module: JsModule.path(module: 'utils', path: '/path/to/utils.js'), ); // Execute a function from a module final result = await engine.eval( source: JsCode.code(''' const { add } = await import('utils'); add(2, 3); '''), ); ``` -------------------------------- ### Get AtomCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/atomCount.html This property retrieves the count of atoms. It is of type PlatformInt64. ```csharp PlatformInt64 get atomCount; ``` -------------------------------- ### Strict Property Access Source: https://pub.dev/documentation/fjs/latest/fjs/JsEvalOptions/strict.html This snippet shows how to get the value of the strict property. ```APIDOC ## GET /websites/pub_dev_fjs/strict ### Description Retrieves the current value of the strict property. ### Method GET ### Endpoint /websites/pub_dev_fjs/strict ### Parameters None ### Request Example None ### Response #### Success Response (200) - **strict** (bool?) - The current value of the strict property. #### Response Example { "strict": true } ``` -------------------------------- ### Create JsAsyncRuntime Instance Source: https://pub.dev/documentation/fjs/latest/fjs/JsAsyncRuntime/JsAsyncRuntime.html Use this constructor to create a new async runtime with default configuration. The runtime is created with no builtin modules. Use `create()` to create a runtime with custom builtin modules. ```dart final runtime = JsAsyncRuntime(); ``` ```dart factory JsAsyncRuntime() => LibFjs.instance.api.crateApiRuntimeJsAsyncRuntimeNew(); ``` -------------------------------- ### JsRuntime Create Method Implementation Source: https://pub.dev/documentation/fjs/latest/fjs/JsRuntime/create.html This is the implementation of the static `create` method for `JsRuntime`. It delegates the creation to the `LibFjs` instance's API. ```dart static Future create( {JsBuiltinOptions? builtins, List? modules}) => LibFjs.instance.api .crateApiRuntimeJsRuntimeCreate(builtins: builtins, modules: modules); ``` -------------------------------- ### Get Memory Usage Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/memoryUsage.html Retrieves memory usage statistics for the engine-owned runtime. ```APIDOC ## memoryUsage abstract method ### Description Returns memory usage statistics for the engine-owned runtime. ### Method Future ### Endpoint N/A (abstract method) ### Parameters None ### Request Body None ### Response #### Success Response (200) - **MemoryUsage** (Future) - Memory usage statistics. ### Response Example ```dart Future memoryUsage(); ``` ``` -------------------------------- ### Compile and Execute JavaScript Module Bundle Source: https://pub.dev/documentation/fjs/latest/index.html Compile a full module graph into a distributable bundle, validate its structure, and then execute it. Imports within the bundle are preserved. ```dart // Compile a full module graph into one distributable bundle. final bundle = await JsBytecode.compileModuleBundle( entry: 'plugins/main.js', modules: [ JsModule.code( module: 'plugins/deps/math.js', code: 'export const double = (value) => value * 2;', ), JsModule.code( module: 'plugins/main.js', code: ''' import { double } from './deps/math.js'; export default { ready: true, answer: double(21) }; ''', ), ], ); // Validate the bundle structure before loading it. await JsBytecode.validateBundle(bundle: bundle); // Execute the bundle entry and cache the involved modules. await engine.evaluateBytecodeBundle(bundle: bundle); // Read exports by importing the entry module afterwards. final result = await engine.eval(source: JsCode.code(''' const { default: plugin } = await import('plugins/main.js'); plugin ''')); print(result.value); // { ready: true, answer: 42 } ``` -------------------------------- ### Get isDisposed Property Source: https://pub.dev/documentation/fjs/latest/fjs/JsAsyncContext/isDisposed.html Check if the underlying Arc is disposed. This is a boolean getter. ```dart bool get isDisposed; ``` -------------------------------- ### Get shapeSize Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/shapeSize.html This snippet shows how to access the shapeSize property. It is of type PlatformInt64. ```csharp PlatformInt64 get shapeSize; ``` -------------------------------- ### JsContext.from Source: https://pub.dev/documentation/fjs/latest/fjs/JsContext/from.html Creates a new JsContext from a JsRuntime. The context inherits the runtime's module configuration and global attachments. ```APIDOC ## POST /websites/pub_dev_fjs/JsContext ### Description Creates a new context from a runtime. The context will inherit the runtime's module configuration and global attachments. ### Method POST ### Endpoint /websites/pub_dev_fjs/JsContext ### Parameters #### Request Body - **runtime** (JsRuntime) - Required - The runtime to create the context from ### Request Example ```json { "runtime": "" } ``` ### Response #### Success Response (200) - **JsContext** (JsContext) - A new JsContext instance #### Response Example ```json { "context": "" } ``` ### Throws If context creation fails ``` -------------------------------- ### JsModuleBytecodeBundle Constructor Source: https://pub.dev/documentation/fjs/latest/fjs/JsModuleBytecodeBundle/JsModuleBytecodeBundle.html Creates a new bundle of bytecode modules. Set `entry` when the bundle will later be executed with `engine.evaluateBytecodeBundle(...)`. Leave it `null` when the bundle is only used for declaration. ```APIDOC ## JsModuleBytecodeBundle constructor ### Description Creates a new bundle of bytecode modules. Set `entry` when the bundle will later be executed with `engine.evaluateBytecodeBundle(...)`. Leave it `null` when the bundle is only used for declaration. ### Parameters #### Request Body - **entry** (String?) - Optional - The entry point for the bundle. - **modules** (List) - Required - A list of JsModuleBytecode objects. ### Request Example ```dart final bundle = JsModuleBytecodeBundle( entry: 'feature/index', modules: [ featureIndexBytecode, sharedUtilBytecode, ], ); ``` ### Implementation ```dart factory JsModuleBytecodeBundle( {String? entry, required List modules}) => LibFjs.instance.api.crateApiSourceJsModuleBytecodeBundleNew( entry: entry, modules: modules); ``` ``` -------------------------------- ### Get jsFuncCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/jsFuncCount.html This property returns the count of JavaScript functions. It is of type PlatformInt64. ```csharp PlatformInt64 get jsFuncCount; ``` -------------------------------- ### Get mallocCount Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/mallocCount.html Retrieves the current count of memory allocations. This is a read-only property. ```C++ PlatformInt64 get mallocCount; ``` -------------------------------- ### Engine Init Method Signature Source: https://pub.dev/documentation/fjs/latest/fjs/JsEngine/init.html This is the method signature for initializing the engine, specifying the required bridge callback. ```dart Future init({required FutureOr Function(JsValue) bridge}); ``` -------------------------------- ### Get jsFuncCodeSize Property Source: https://pub.dev/documentation/fjs/latest/fjs/MemoryUsage/jsFuncCodeSize.html Use this to retrieve the value of the jsFuncCodeSize property. It returns a PlatformInt64. ```csharp PlatformInt64 get jsFuncCodeSize; ``` -------------------------------- ### JsAsyncRuntime Constructor Source: https://pub.dev/documentation/fjs/latest/fjs/JsAsyncRuntime/JsAsyncRuntime.html Creates a new async runtime with default configuration. The runtime is created with no builtin modules. Use `create()` to create a runtime with custom builtin modules. ```APIDOC ## JsAsyncRuntime() ### Description Creates a new async runtime with default configuration. The runtime is created with no builtin modules. Use `create()` to create a runtime with custom builtin modules. ### Method Constructor ### Endpoint N/A ### Parameters None ### Request Body None ### Response #### Success Response (200) - **JsAsyncRuntime** (object) - A new `JsAsyncRuntime` instance #### Response Example ```dart final runtime = JsAsyncRuntime(); ``` ### Implementation ```dart factory JsAsyncRuntime() => LibFjs.instance.api.crateApiRuntimeJsAsyncRuntimeNew(); ``` ``` -------------------------------- ### JsEngineRuntimeOptions Configuration Source: https://pub.dev/documentation/fjs/latest/index.html Defines runtime options for a JavaScript engine, allowing configuration of memory limits, GC thresholds, stack size, and informational strings. ```dart sealed class JsEngineRuntimeOptions { const factory JsEngineRuntimeOptions({ BigInt? memoryLimit, BigInt? gcThreshold, BigInt? maxStackSize, String? info, }); } ```