Skip to content

Add completion thread control and script argument passing to runScriptFileAsync#3

Draft
Copilot wants to merge 11 commits intomainfrom
copilot/add-api-run-js-script-async
Draft

Add completion thread control and script argument passing to runScriptFileAsync#3
Copilot wants to merge 11 commits intomainfrom
copilot/add-api-run-js-script-async

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 25, 2026

Extends runScriptFileAsync API with two capabilities: completion handler thread control and runtime script parameterization via string arguments.

Changes

Thread Control

  • Added runOnMainThread parameter (defaults to YES for backward compatibility)
  • Eliminates thread context switch overhead when UI updates aren't needed
  • All error paths respect the thread preference

Script Arguments

  • Added argument parameter to pass strings to scripts
  • Argument accessible in JavaScript as __scriptArgument global variable
  • Set in V8 context before script execution

Backward Compatibility

  • Existing method signatures delegate to extended version with defaults
  • All existing code continues to work unchanged

API

// Full signature
- (void)runScriptFileAsync:(NSString*)filePath
                  argument:(NSString*)argument
          runOnMainThread:(BOOL)runOnMainThread
                completion:(void(^)(id result, NSError* error))completion;

// Convenience wrappers (maintain existing behavior)
- (void)runScriptFileAsync:(NSString*)filePath completion:(void(^)(id, NSError*))completion;
- (void)runScriptFileAsync:(NSString*)filePath runOnMainThread:(BOOL)runOnMainThread completion:(void(^)(id, NSError*))completion;

Usage

// Background completion for data processing
[runtime runScriptFileAsync:@"process.js"
                    argument:@"{\"userId\":123}"
            runOnMainThread:NO
                  completion:^(id result, NSError* error) {
    // Runs on background thread
}];
// process.js
const data = JSON.parse(__scriptArgument);
return { userId: data.userId, status: 'completed' };

Tests

Added 11 test cases covering:

  • Background thread completion with thread verification via NSThread.isMainThread
  • Simple string arguments, JSON parsing, nil handling
  • Mixed threading scenarios

⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] Add new API to run JS script file async Add async JavaScript file execution API with native result callbacks Mar 25, 2026
Copilot AI requested a review from farfromrefug March 25, 2026 17:04
Copilot AI changed the title Add async JavaScript file execution API with native result callbacks Add optional background thread completion to runScriptFileAsync Mar 25, 2026
Copilot AI changed the title Add optional background thread completion to runScriptFileAsync Add completion thread control and script argument passing to runScriptFileAsync Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants