JSWorkerConstructor.cpp [plain text]
#include "config.h"
#if ENABLE(WORKERS)
#include "JSWorkerConstructor.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "JSDOMWindowCustom.h"
#include "JSWorker.h"
#include "Worker.h"
using namespace JSC;
namespace WebCore {
const ClassInfo JSWorkerConstructor::s_info = { "WorkerConstructor", 0, 0, 0 };
JSWorkerConstructor::JSWorkerConstructor(ExecState* exec)
: DOMObject(JSWorkerConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype()))
{
putDirect(exec->propertyNames().prototype, JSWorkerPrototype::self(exec, exec->lexicalGlobalObject()), None);
putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum);
}
static JSObject* constructWorker(ExecState* exec, JSObject*, const ArgList& args)
{
if (args.size() == 0)
return throwError(exec, SyntaxError, "Not enough arguments");
UString scriptURL = args.at(0).toString(exec);
if (exec->hadException())
return 0;
DOMWindow* window = asJSDOMWindow(exec->lexicalGlobalObject())->impl();
ExceptionCode ec = 0;
RefPtr<Worker> worker = Worker::create(scriptURL, window->document(), ec);
setDOMException(exec, ec);
return asObject(toJS(exec, worker.release()));
}
ConstructType JSWorkerConstructor::getConstructData(ConstructData& constructData)
{
constructData.native.function = constructWorker;
return ConstructTypeHost;
}
}
#endif // ENABLE(WORKERS)