#549: working <<run JavaScript>> method

This commit is contained in:
Cameron Kaiser 2019-03-21 22:52:17 -07:00
parent 64890af9bf
commit 860cb0f37a
3 changed files with 20 additions and 9 deletions

View File

@ -295,13 +295,13 @@
<cocoa class="NSScriptCommand"/>
<direct-parameter type="specifier" description="the object to reload"/>
</command>
<command name="runJS" code="104FxrJS" description="Runs JavaScript in the context of an object.">
<command name="run" code="104FxrJS" description="Runs JavaScript in the context of an object.">
<cocoa class="NSScriptCommand"/>
<direct-parameter type="specifier" description="the object context"/>
<parameter name="script" code="scpt" type="text" description="The script source text.">
<parameter name="JavaScript" code="jscp" type="text" description="the JavaScript source text">
<cocoa key="script"/>
</parameter>
<result type="text" description="String value returned by the script."/>
<result type="text" description="string value returned by the script"/>
</command>
<class name="tab" code="BTab" description="A %MAC_APP_NAME% browser window tab." inherits="item" plural="tabs">
<cocoa class="GeckoTab"/>
@ -332,7 +332,7 @@
<responds-to name="reload">
<cocoa method="handleReloadScriptCommand:"/>
</responds-to>
<responds-to name="runJS">
<responds-to name="run">
<cocoa method="handleRunJavaScriptCommand:"/>
</responds-to>
<!--

View File

@ -980,10 +980,20 @@ BrowserGlue.prototype = {
}
},
runScriptInTabAtIndexInWindow : function(index, window_index,
script) {
Services.console.logStringMessage("Got script: "+script);
throw Components.Exception("NYI", Cr.NS_ERROR_FAILURE);
return null;
script, rval) {
try {
let win = this.getWindow(window_index);
let tab = win.gBrowser.tabs[index].linkedBrowser;
let f = new Function("window", "document", ""+script);
let g = (t) => {
return f(t.contentWindow, t.contentDocument);
};
rval.value = g(tab);
} catch(e) {
Services.console.logStringMessage("AS-to-JS error: "+e);
return false;
}
return true;
}
}

View File

@ -892,9 +892,10 @@ static BOOL didInit = NO;
NSString *script = [args objectForKey:@"script"];
if (script) {
nsAutoCString s, r;
bool ok;
bool ok = false;
s.Assign([script UTF8String]);
r.Truncate();
if (NS_SUCCEEDED(applescriptService->RunScriptInTabAtIndexInWindow(mIndex,
[mWindow orderedIndex],
s, r, &ok))) {