@@ -72,9 +72,17 @@ Future<void> main() async {
7272### 🔧 2. Create a JavaScript Engine
7373
7474``` dart
75- // Create runtime and context
76- final runtime = JsAsyncRuntime();
77- final context = await JsAsyncContext.from(rt: runtime);
75+ // Create runtime with built-in options
76+ final runtime = await JsAsyncRuntime.withOptions(
77+ builtin: JsBuiltinOptions(
78+ fetch: true,
79+ console: true,
80+ timers: true,
81+ ),
82+ );
83+
84+ // Create context
85+ final context = await JsAsyncContext.from(runtime);
7886
7987// Create engine with bridge support
8088final engine = JsEngine(context);
@@ -101,16 +109,10 @@ final asyncResult = await engine.eval(JsCode.code('''
101109'''));
102110```
103111
104- ### 🌐 4. Enable Built-in Modules
112+ ### 🌐 4. Use Built-in Modules
105113
106114``` dart
107- // Enable fetch and console APIs
108- await engine.enableBuiltinModule(const JsBuiltinOptions(
109- fetch: true,
110- console: true,
111- timers: true,
112- ));
113-
115+ // Built-in modules are enabled during runtime creation
114116// Now you can use fetch, console.log, setTimeout, etc.
115117await engine.eval(JsCode.code('''
116118 console.log('Hello from JavaScript!');
@@ -121,7 +123,7 @@ await engine.eval(JsCode.code('''
121123### 📦 5. Work with Modules
122124
123125``` dart
124- // Declare a module
126+ // Declare a single module
125127const moduleCode = '''
126128export function greet(name) {
127129 return `Hello, ${name}!`;
@@ -130,15 +132,26 @@ export function greet(name) {
130132export const version = '1.0.0';
131133''';
132134
133- await engine.declareModule (
135+ await engine.declareNewModule (
134136 JsModule.code(module: 'greeting', code: moduleCode)
135137);
136138
137- // Use the module
139+ // Declare multiple modules at once
140+ await engine.declareNewModules([
141+ JsModule.code('math', 'export const add = (a, b) => a + b;'),
142+ JsModule.code('string', 'export const reverse = (s) => s.split("").reverse().join("");'),
143+ ]);
144+
145+ // Use the modules
138146await engine.eval(JsCode.code('''
139147 import { greet, version } from 'greeting';
148+ import { add } from 'math';
149+ import { reverse } from 'string';
150+
140151 console.log(greet('Flutter'));
141152 console.log('Version:', version);
153+ console.log('Add 2 + 3:', add(2, 3));
154+ console.log('Reverse hello:', reverse('hello'));
142155'''));
143156```
144157
@@ -242,13 +255,11 @@ class JsEngine {
242255 // Execute JavaScript code
243256 Future<JsValue> eval(JsCode source, {JsEvalOptions? options, Duration? timeout});
244257
245- // Enable built-in modules
246- Future<JsValue> enableBuiltinModule(JsBuiltinOptions options, {Duration? timeout});
247-
248258 // Module operations
249- Future<JsValue> declareModule(JsModule module, {Duration? timeout});
259+ Future<JsValue> declareNewModule(JsModule module, {Duration? timeout});
260+ Future<JsValue> declareNewModules(List<JsModule> modules, {Duration? timeout});
250261 Future<JsValue> evaluateModule(JsModule module, {Duration? timeout});
251- Future<JsValue> importModule(String specifier, {Duration? timeout});
262+ Future<JsValue> clearNewModules( {Duration? timeout});
252263
253264 // Cleanup
254265 Future<void> dispose();
@@ -318,11 +329,6 @@ Check out the [example](example/) directory for more comprehensive examples incl
318329- ** Production** : Real iOS devices (arm64) are fully supported with normal performance
319330- ** Minimum iOS Version** : Requires iOS 12.0 or later due to native library dependencies
320331
321- ### Android Platform Limitations
322-
323- - ** Crypto Module** : The built-in crypto module is not supported on Android platform
324- - ** Impact** : Applications requiring cryptographic functions on Android should use Dart's crypto libraries or platform-specific implementations
325-
326332## 🤝 Contributing
327333
328334Contributions are welcome! Please feel free to submit a Pull Request.
0 commit comments