Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to execute JavaScript with JavaScriptCore framework?
    primarykey
    data
    text
    <p>I have implemented following code to execute JavaScript file of <a href="http://pivotal.github.com/jasmine/" rel="nofollow">Jasmine Test</a> Framework. </p> <pre><code>NSMutableArray * fArr = [[NSBundle mainBundle] pathsForResourcesOfType:@"js" inDirectory:@"scripts/JS_TestFramework/lib/jasmine-1.1.0"]; NSMutableString *fullFrameworkScript = nil; NSString *script; for (int i = fArr.count-1; i &gt;= 0; i--) { NSMutableString* filePath = [fArr objectAtIndex:i]; fullFrameworkScript = [NSMutableString string]; NSError* error; script = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&amp;error]; if(script) { [fullFrameworkScript appendString:script]; } } JSValueRef result; if(fullFrameworkScript) { JSStringRef scriptJS = JSStringCreateWithCFString(fullFrameworkScript); JSValueRef exception = NULL; result = JSEvaluateScript(context, scriptJS, NULL, NULL, 1, &amp;exception); if(exception) { [self logException:exception]; exception = NULL; } JSStringRelease(scriptJS); } JSStringRef step1 = JSStringCreateWithCFString(@"jasmine.getEnv().addReporter(new jasmine.TrivialReporter())"); JSValueRef exception = NULL; JSObjectRef fn = JSObjectMakeFunction(context, step1, 0, NULL, JSStringCreateWithCFString(script), NULL, 0, NULL); result = JSObjectCallAsFunction(context, fn, NULL, 0, NULL, &amp;exception); if(exception) { [self logException:exception]; exception = NULL; } JSStringRelease(step1); [MTPScriptExecutionContext removeAllObjects]; JSStringRef htmlResult = JSValueToStringCopy(context, result, NULL); NSString *htmlData = [NSMakeCollectable(JSStringCopyCFString(kCFAllocatorDefault, htmlResult)) autorelease]; JSStringRelease(htmlResult); return htmlData; </code></pre> <p>This is my function which returns HTML data... When i am executing the script i am getting following error at Exception:</p> <pre><code>Exception = Can't find variable: jasmine </code></pre> <p>Though my script has declared <code>jasmine</code> variable at first line. What else could be the problem with above code???? Is their any other way to execute JavaScript??</p> <p>One more question : Does JavaScriptCore framework supports DOM and other functionality of HTML??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload