static JSObject* constructAudio(ExecState* exec, JSObject* constructor, const ArgList& args) { JSAudioConstructor* jsAudio = static_cast<JSAudioConstructor*>(constructor); // FIXME: Why doesn't this need the call toJS on the document like JSImageConstructor? Document* document = jsAudio->document(); if (!document) return throwError(exec, ReferenceError, "Audio constructor associated document is unavailable"); RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, document); audio->setAutobuffer(true); if (args.size() > 0) { audio->setSrc(args.at(0).toString(exec)); audio->scheduleLoad(); } return asObject(toJS(exec, jsAudio->globalObject(), audio.release())); }
static EncodedJSValue JSC_HOST_CALL constructAudio(ExecState* exec) { JSAudioConstructor* jsConstructor = static_cast<JSAudioConstructor*>(exec->callee()); Document* document = jsConstructor->document(); if (!document) return throwVMError(exec, createReferenceError(exec, "Audio constructor associated document is unavailable")); // Calling toJS on the document causes the JS document wrapper to be // added to the window object. This is done to ensure that JSDocument::visitChildren // will be called, which will cause the audio element to be marked if necessary. toJS(exec, jsConstructor->globalObject(), document); // FIXME: This converts an undefined argument to the string "undefined", but possibly we // should treat it as if no argument was passed instead, by checking the value of exec->argument // rather than looking at exec->argumentCount. String src; if (exec->argumentCount() > 0) src = ustringToString(exec->argument(0).toString(exec)); return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), HTMLAudioElement::createForJSConstructor(document, src)))); }