EncodedJSValue JSC_HOST_CALL JSSharedWorkerConstructor::constructJSSharedWorker(ExecState* exec) { JSSharedWorkerConstructor* jsConstructor = static_cast<JSSharedWorkerConstructor*>(exec->callee()); if (exec->argumentCount() < 1) return throwVMError(exec, createSyntaxError(exec, "Not enough arguments")); UString scriptURL = exec->argument(0).toString(exec); UString name; if (exec->argumentCount() > 1) name = exec->argument(1).toString(exec); if (exec->hadException()) return JSValue::encode(JSValue()); // FIXME: We need to use both the dynamic scope and the lexical scope (dynamic scope for resolving the worker URL) DOMWindow* window = asJSDOMWindow(exec->lexicalGlobalObject())->impl(); ExceptionCode ec = 0; RefPtr<SharedWorker> worker = SharedWorker::create(ustringToString(scriptURL), ustringToString(name), window->document(), ec); if (ec) { setDOMException(exec, ec); return JSValue::encode(JSValue()); } return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), worker.release()))); }
static JSObject* constructSharedWorker(ExecState* exec, JSObject* constructor, const ArgList& args) { JSSharedWorkerConstructor* jsConstructor = static_cast<JSSharedWorkerConstructor*>(constructor); if (args.size() < 1) return throwError(exec, SyntaxError, "Not enough arguments"); UString scriptURL = args.at(0).toString(exec); UString name; if (args.size() > 1) name = args.at(1).toString(exec); if (exec->hadException()) return 0; // FIXME: We need to use both the dynamic scope and the lexical scope (dynamic scope for resolving the worker URL) DOMWindow* window = asJSDOMWindow(exec->lexicalGlobalObject())->impl(); ExceptionCode ec = 0; RefPtr<SharedWorker> worker = SharedWorker::create(scriptURL, name, window->document(), ec); setDOMException(exec, ec); return asObject(toJS(exec, jsConstructor->globalObject(), worker.release())); }