本文整理汇总了C++中JSValue::isConstructor方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isConstructor方法的具体用法?C++ JSValue::isConstructor怎么用?C++ JSValue::isConstructor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::isConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reflectObjectConstruct
// https://tc39.github.io/ecma262/#sec-reflect.construct
EncodedJSValue JSC_HOST_CALL reflectObjectConstruct(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue target = exec->argument(0);
if (!target.isObject())
return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the first argument be a constructor")));
ConstructData constructData;
ConstructType constructType;
if (!target.isConstructor(constructType, constructData))
return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the first argument be a constructor")));
JSValue newTarget = target;
if (exec->argumentCount() >= 3) {
newTarget = exec->argument(2);
if (!newTarget.isConstructor())
return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the third argument be a constructor if present")));
}
MarkedArgumentBuffer arguments;
JSObject* argumentsObject = jsDynamicCast<JSObject*>(exec->argument(1));
if (!argumentsObject)
return JSValue::encode(throwTypeError(exec, scope, ASCIILiteral("Reflect.construct requires the second argument be an object")));
createListFromArrayLike(exec, argumentsObject, RuntimeTypeMaskAllTypes, ASCIILiteral("This error must not be raised"), [&] (JSValue value, RuntimeType) -> bool {
arguments.append(value);
return false;
});
RETURN_IF_EXCEPTION(scope, encodedJSValue());
scope.release();
return JSValue::encode(construct(exec, target, constructType, constructData, arguments, newTarget));
}
示例2: reflectObjectConstruct
// https://tc39.github.io/ecma262/#sec-reflect.construct
EncodedJSValue JSC_HOST_CALL reflectObjectConstruct(ExecState* exec)
{
JSValue target = exec->argument(0);
if (!target.isObject())
return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the first argument be a constructor")));
ConstructData constructData;
ConstructType constructType;
if (!target.isConstructor(constructType, constructData))
return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the first argument be a constructor")));
JSValue newTarget = target;
if (exec->argumentCount() >= 3) {
newTarget = exec->argument(2);
if (!newTarget.isConstructor())
return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the third argument be a constructor if present")));
}
MarkedArgumentBuffer arguments;
JSObject* argumentsObject = jsDynamicCast<JSObject*>(exec->argument(1));
if (!argumentsObject)
return JSValue::encode(throwTypeError(exec, ASCIILiteral("Reflect.construct requires the second argument be an object")));
createListFromArrayLike(exec, argumentsObject, RuntimeTypeMaskAllTypes, ASCIILiteral("This error must not be raised"), [&] (JSValue value, RuntimeType) -> bool {
arguments.append(value);
return false;
});
if (exec->hadException())
return JSValue::encode(jsUndefined());
return JSValue::encode(construct(exec, target, constructType, constructData, arguments, newTarget));
}
示例3: define
// https://html.spec.whatwg.org/#dom-customelementsregistry-define
JSValue JSCustomElementsRegistry::define(ExecState& state)
{
if (UNLIKELY(state.argumentCount() < 2))
return state.vm().throwException(&state, createNotEnoughArgumentsError(&state));
AtomicString localName(state.uncheckedArgument(0).toString(&state)->toAtomicString(&state));
if (UNLIKELY(state.hadException()))
return jsUndefined();
JSValue constructorValue = state.uncheckedArgument(1);
if (!constructorValue.isConstructor())
return throwTypeError(&state, ASCIILiteral("The second argument must be a constructor"));
JSObject* constructor = constructorValue.getObject();
// FIXME: Throw a TypeError if constructor doesn't inherit from HTMLElement.
// https://github.com/w3c/webcomponents/issues/541
switch (Document::validateCustomElementName(localName)) {
case CustomElementNameValidationStatus::Valid:
break;
case CustomElementNameValidationStatus::ConflictsWithBuiltinNames:
return throwSyntaxError(&state, ASCIILiteral("Custom element name cannot be same as one of the builtin elements"));
case CustomElementNameValidationStatus::NoHyphen:
return throwSyntaxError(&state, ASCIILiteral("Custom element name must contain a hyphen"));
case CustomElementNameValidationStatus::ContainsUpperCase:
return throwSyntaxError(&state, ASCIILiteral("Custom element name cannot contain an upper case letter"));
}
// FIXME: Check re-entrancy here.
// https://github.com/w3c/webcomponents/issues/545
CustomElementsRegistry& registry = wrapped();
if (registry.findInterface(localName)) {
throwNotSupportedError(state, ASCIILiteral("Cannot define multiple custom elements with the same tag name"));
return jsUndefined();
}
if (registry.containsConstructor(constructor)) {
throwNotSupportedError(state, ASCIILiteral("Cannot define multiple custom elements with the same class"));
return jsUndefined();
}
auto& vm = globalObject()->vm();
JSValue prototypeValue = constructor->get(&state, vm.propertyNames->prototype);
if (state.hadException())
return jsUndefined();
if (!prototypeValue.isObject())
return throwTypeError(&state, ASCIILiteral("Custom element constructor's prototype must be an object"));
JSObject& prototypeObject = *asObject(prototypeValue);
QualifiedName name(nullAtom, localName, HTMLNames::xhtmlNamespaceURI);
auto elementInterface = JSCustomElementInterface::create(name, constructor, globalObject());
auto* connectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "connectedCallback"));
if (state.hadException())
return jsUndefined();
if (connectedCallback)
elementInterface->setConnectedCallback(connectedCallback);
auto* disconnectedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "disconnectedCallback"));
if (state.hadException())
return jsUndefined();
if (disconnectedCallback)
elementInterface->setDisconnectedCallback(disconnectedCallback);
// FIXME: Add the support for adoptedCallback.
getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "adoptedCallback"));
if (state.hadException())
return jsUndefined();
auto* attributeChangedCallback = getCustomElementCallback(state, prototypeObject, Identifier::fromString(&vm, "attributeChangedCallback"));
if (state.hadException())
return jsUndefined();
if (attributeChangedCallback) {
auto value = convertOptional<Vector<String>>(state, constructor->get(&state, Identifier::fromString(&state, "observedAttributes")));
if (state.hadException())
return jsUndefined();
if (value)
elementInterface->setAttributeChangedCallback(attributeChangedCallback, *value);
}
PrivateName uniquePrivateName;
globalObject()->putDirect(vm, uniquePrivateName, constructor);
registry.addElementDefinition(WTFMove(elementInterface));
// FIXME: 17. Let map be registry's upgrade candidates map.
// FIXME: 18. Upgrade a newly-defined element given map and definition.
// FIXME: 19. Resolve whenDefined promise.
return jsUndefined();
}