#include "config.h"
#include "JSBase.h"
#include "APICast.h"
#include "SourceCode.h"
#include <kjs/ExecState.h>
#include <kjs/JSGlobalObject.h>
#include <kjs/JSLock.h>
#include <kjs/interpreter.h>
#include <kjs/object.h>
using namespace KJS;
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
ExecState* exec = toJS(ctx);
JSObject* jsThisObject = toJS(thisObject);
UString::Rep* scriptRep = toJS(script);
UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
SourceCode source = makeSource(UString(scriptRep), UString(sourceURLRep), startingLineNumber);
Completion completion = Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), source, jsThisObject);
if (completion.complType() == Throw) {
if (exception)
*exception = toRef(completion.value());
return 0;
}
if (completion.value())
return toRef(completion.value());
return toRef(jsUndefined());
}
bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
JSLock lock;
ExecState* exec = toJS(ctx);
UString::Rep* scriptRep = toJS(script);
UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
SourceCode source = makeSource(UString(scriptRep), UString(sourceURLRep), startingLineNumber);
Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), source);
if (completion.complType() == Throw) {
if (exception)
*exception = toRef(completion.value());
return false;
}
return true;
}
void JSGarbageCollect(JSContextRef)
{
JSLock lock;
if (!Collector::isBusy())
Collector::collect();
}