void V8OscillatorNode::typeAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { ExceptionState exceptionState(ExceptionState::SetterContext, "type", "OscillatorNode", info.Holder(), info.GetIsolate()); v8::Handle<v8::Object> holder = info.Holder(); OscillatorNode* imp = V8OscillatorNode::toNative(holder); if (value->IsNumber()) { uint32_t type = toUInt32(value, exceptionState); if (exceptionState.throwIfNeeded()) return; if (!imp->setType(type)) { exceptionState.throwTypeError("Illegal OscillatorNode type"); exceptionState.throwIfNeeded(); } return; } if (value->IsString()) { String type = toCoreString(value.As<v8::String>()); if (type == "sine" || type == "square" || type == "sawtooth" || type == "triangle") { imp->setType(type); return; } } exceptionState.throwTypeError("Illegal OscillatorNode type"); exceptionState.throwIfNeeded(); }
void V8OscillatorNode::typeAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { v8::Handle<v8::Object> holder = info.Holder(); OscillatorNode* imp = V8OscillatorNode::toNative(holder); #if ENABLE(LEGACY_WEB_AUDIO) if (value->IsNumber()) { bool ok = false; uint32_t type = toUInt32(value, ok); if (!ok || !imp->setType(type)) throwError(v8TypeError, "Illegal OscillatorNode type", info.GetIsolate()); return; } #endif if (value->IsString()) { String type = toWebCoreString(value); if (type == "sine" || type == "square" || type == "sawtooth" || type == "triangle") { imp->setType(type); return; } } throwError(v8TypeError, "Illegal OscillatorNode type", info.GetIsolate()); }
void JSOscillatorNode::setType(ExecState* exec, JSValue value) { OscillatorNode* imp = impl(); #if ENABLE(LEGACY_WEB_AUDIO) if (value.isNumber()) { uint32_t type = value.toUInt32(exec); if (!imp->setType(type)) exec->vm().throwException(exec, createTypeError(exec, "Illegal OscillatorNode type")); return; } #endif if (value.isString()) { String type = value.toString(exec)->value(exec); if (type == "sine" || type == "square" || type == "sawtooth" || type == "triangle") { imp->setType(type); return; } } exec->vm().throwException(exec, createTypeError(exec, "Illegal OscillatorNode type")); }
OscillatorNode* OscillatorNode::create(BaseAudioContext* context, const OscillatorOptions& options, ExceptionState& exceptionState) { OscillatorNode* node = create(*context, exceptionState); if (!node) return nullptr; node->handleChannelOptions(options, exceptionState); if (options.hasType()) { if (options.type() == "custom" && !options.hasPeriodicWave()) { exceptionState.throwDOMException(InvalidStateError, "'type' cannot be set to 'custom' " "without also specifying " "'periodicWave'"); return nullptr; } if (options.type() != "custom" && options.hasPeriodicWave()) { exceptionState.throwDOMException(InvalidStateError, "'type' MUST be 'custom' instead of '" + options.type() + "' if 'periodicWave' is also given"); return nullptr; } // At this both type and periodicWave are consistently defined. In that // case, don't set the type if periodicWave is specified because that // will cause an (incorrect) error to be signaled. if (options.type() != "custom") node->setType(options.type(), exceptionState); } if (options.hasDetune()) node->detune()->setValue(options.detune()); if (options.hasFrequency()) node->frequency()->setValue(options.frequency()); if (options.hasPeriodicWave()) node->setPeriodicWave(options.periodicWave()); return node; }