Jasmine Test Frameworkの JavaScript ファイルを実行するために、次のコードを実装しました。
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 >= 0; i--)
{
NSMutableString* filePath = [fArr objectAtIndex:i];
fullFrameworkScript = [NSMutableString string];
NSError* error;
script = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
if(script)
{
[fullFrameworkScript appendString:script];
}
}
JSValueRef result;
if(fullFrameworkScript)
{
JSStringRef scriptJS = JSStringCreateWithCFString(fullFrameworkScript);
JSValueRef exception = NULL;
result = JSEvaluateScript(context, scriptJS, NULL, NULL, 1, &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, &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;
これは、HTML データを返す関数です...スクリプトを実行すると、例外で次のエラーが発生します。
Exception = Can't find variable: jasmine
私のスクリプトはjasmine
最初の行で変数を宣言していますが。上記のコードで他に何が問題になる可能性がありますか???? JavaScript を実行する他の方法はありますか??
もう 1 つの質問: JavaScriptCore フレームワークは DOM やその他の HTML の機能をサポートしていますか?