本文整理汇总了C++中JSValue::isFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isFunction方法的具体用法?C++ JSValue::isFunction怎么用?C++ JSValue::isFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::isFunction方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getRuntimeTypeForValue
RuntimeType TypeSet::getRuntimeTypeForValue(JSValue v)
{
RuntimeType ret;
if (v.isFunction())
ret = TypeFunction;
else if (v.isUndefined())
ret = TypeUndefined;
else if (v.isNull())
ret = TypeNull;
else if (v.isBoolean())
ret = TypeBoolean;
else if (v.isMachineInt())
ret = TypeMachineInt;
else if (v.isNumber())
ret = TypeNumber;
else if (v.isString())
ret = TypeString;
else if (v.isPrimitive())
ret = TypePrimitive;
else if (v.isObject())
ret = TypeObject;
else
CRASH();
return ret;
}
示例2: runtimeTypeForValue
RuntimeType runtimeTypeForValue(JSValue value)
{
if (UNLIKELY(!value))
return TypeNothing;
if (value.isUndefined())
return TypeUndefined;
if (value.isNull())
return TypeNull;
if (value.isAnyInt())
return TypeAnyInt;
if (value.isNumber())
return TypeNumber;
if (value.isString())
return TypeString;
if (value.isBoolean())
return TypeBoolean;
if (value.isObject())
return TypeObject;
if (value.isFunction())
return TypeFunction;
if (value.isSymbol())
return TypeSymbol;
return TypeNothing;
}
示例3: getCustomElementCallback
static JSObject* getCustomElementCallback(ExecState& state, JSObject& prototype, const Identifier& id)
{
JSValue callback = prototype.get(&state, id);
if (state.hadException())
return nullptr;
if (callback.isUndefined())
return nullptr;
if (!callback.isFunction()) {
throwTypeError(&state, ASCIILiteral("A custom element callback must be a function"));
return nullptr;
}
return callback.getObject();
}
示例4: queueMicrotask
JSValue JSWorkerGlobalScope::queueMicrotask(ExecState& state)
{
VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (UNLIKELY(state.argumentCount() < 1))
return throwException(&state, scope, createNotEnoughArgumentsError(&state));
JSValue functionValue = state.uncheckedArgument(0);
if (UNLIKELY(!functionValue.isFunction(vm)))
return JSValue::decode(throwArgumentMustBeFunctionError(state, scope, 0, "callback", "WorkerGlobalScope", "queueMicrotask"));
scope.release();
Base::queueMicrotask(JSC::createJSMicrotask(vm, functionValue));
return jsUndefined();
}
示例5: invoke
JSPromise* ReadableJSStream::invoke(ExecState& state, const char* propertyName, JSValue parameter)
{
JSValue function = getPropertyFromObject(state, *m_source.get(), propertyName);
if (state.hadException())
return nullptr;
if (!function.isFunction()) {
if (!function.isUndefined())
throwVMError(&state, createTypeError(&state, ASCIILiteral("ReadableStream trying to call a property that is not callable")));
return nullptr;
}
MarkedArgumentBuffer arguments;
arguments.append(parameter);
JSPromise* promise = jsDynamicCast<JSPromise*>(callFunction(state, function, m_source.get(), arguments));
ASSERT(!(promise && state.hadException()));
return promise;
}
示例6: parseFunctionImportSection
void WASMModuleParser::parseFunctionImportSection(ExecState* exec)
{
uint32_t numberOfFunctionImports;
uint32_t numberOfFunctionImportSignatures;
READ_COMPACT_UINT32_OR_FAIL(numberOfFunctionImports, "Cannot read the number of function imports.");
READ_COMPACT_UINT32_OR_FAIL(numberOfFunctionImportSignatures, "Cannot read the number of function import signatures.");
m_module->functionImports().reserveInitialCapacity(numberOfFunctionImports);
m_module->functionImportSignatures().reserveInitialCapacity(numberOfFunctionImportSignatures);
m_module->importedFunctions().reserveInitialCapacity(numberOfFunctionImports);
for (uint32_t functionImportIndex = 0; functionImportIndex < numberOfFunctionImports; ++functionImportIndex) {
WASMFunctionImport functionImport;
READ_STRING_OR_FAIL(functionImport.functionName, "Cannot read the function import name.");
m_module->functionImports().uncheckedAppend(functionImport);
uint32_t numberOfSignatures;
READ_COMPACT_UINT32_OR_FAIL(numberOfSignatures, "Cannot read the number of signatures.");
FAIL_IF_FALSE(numberOfSignatures <= numberOfFunctionImportSignatures - m_module->functionImportSignatures().size(), "The number of signatures is incorrect.");
for (uint32_t i = 0; i < numberOfSignatures; ++i) {
WASMFunctionImportSignature functionImportSignature;
READ_COMPACT_UINT32_OR_FAIL(functionImportSignature.signatureIndex, "Cannot read the signature index.");
FAIL_IF_FALSE(functionImportSignature.signatureIndex < m_module->signatures().size(), "The signature index is incorrect.");
functionImportSignature.functionImportIndex = functionImportIndex;
m_module->functionImportSignatures().uncheckedAppend(functionImportSignature);
}
JSValue value;
getImportedValue(exec, functionImport.functionName, value);
PROPAGATE_ERROR();
FAIL_IF_FALSE(value.isFunction(), "\"" + functionImport.functionName + "\" is not a function.");
JSFunction* function = jsCast<JSFunction*>(value.asCell());
m_module->importedFunctions().uncheckedAppend(WriteBarrier<JSFunction>(m_vm, m_module.get(), function));
}
FAIL_IF_FALSE(m_module->functionImportSignatures().size() == numberOfFunctionImportSignatures, "The number of function import signatures is incorrect.");
}
示例7: encode
static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* exec)
{
auto& vm = exec->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* globalObject = exec->lexicalGlobalObject();
// If moduleObject is not a WebAssembly.Module instance, a TypeError is thrown.
JSWebAssemblyModule* jsModule = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->argument(0));
if (!jsModule)
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("first argument to WebAssembly.Instance must be a WebAssembly.Module"), defaultSourceAppender, runtimeTypeForValue(exec->argument(0)))));
const Wasm::ModuleInformation& moduleInformation = jsModule->moduleInformation();
// If the importObject parameter is not undefined and Type(importObject) is not Object, a TypeError is thrown.
JSValue importArgument = exec->argument(1);
JSObject* importObject = importArgument.getObject();
if (!importArgument.isUndefined() && !importObject)
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("second argument to WebAssembly.Instance must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument))));
// If the list of module.imports is not empty and Type(importObject) is not Object, a TypeError is thrown.
if (moduleInformation.imports.size() && !importObject)
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("second argument to WebAssembly.Instance must be Object because the WebAssembly.Module has imports"), defaultSourceAppender, runtimeTypeForValue(importArgument))));
Identifier moduleKey = Identifier::fromUid(PrivateName(PrivateName::Description, "WebAssemblyInstance"));
WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(exec, vm, globalObject->webAssemblyModuleRecordStructure(), moduleKey, moduleInformation);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
Structure* instanceStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), globalObject->WebAssemblyInstanceStructure());
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, instanceStructure, jsModule, moduleRecord->getModuleNamespace(exec));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
{
// Always start with a dummy Memory, so that wasm -> wasm thunks avoid checking for a nullptr Memory when trying to set pinned registers.
Wasm::Memory memory;
instance->setMemory(vm, JSWebAssemblyMemory::create(vm, exec->lexicalGlobalObject()->WebAssemblyMemoryStructure(), WTFMove(memory)));
}
// Let funcs, memories and tables be initially-empty lists of callable JavaScript objects, WebAssembly.Memory objects and WebAssembly.Table objects, respectively.
// Let imports be an initially-empty list of external values.
unsigned numImportFunctions = 0;
unsigned numImportGlobals = 0;
bool hasMemoryImport = false;
bool hasTableImport = false;
// For each import i in module.imports:
for (auto& import : moduleInformation.imports) {
// 1. Let o be the resultant value of performing Get(importObject, i.module_name).
JSValue importModuleValue = importObject->get(exec, import.module);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
// 2. If Type(o) is not Object, throw a TypeError.
if (!importModuleValue.isObject())
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("import must be an object"), defaultSourceAppender, runtimeTypeForValue(importModuleValue))));
// 3. Let v be the value of performing Get(o, i.item_name)
JSObject* object = jsCast<JSObject*>(importModuleValue);
JSValue value = object->get(exec, import.field);
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
switch (import.kind) {
case Wasm::ExternalKind::Function: {
// 4. If i is a function import:
// i. If IsCallable(v) is false, throw a WebAssembly.LinkError.
if (!value.isFunction())
return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("import function must be callable"))));
JSCell* cell = value.asCell();
// ii. If v is an Exported Function Exotic Object:
if (WebAssemblyFunction* importedExport = jsDynamicCast<WebAssemblyFunction*>(vm, cell)) {
// a. If the signature of v does not match the signature of i, throw a WebAssembly.LinkError.
Wasm::SignatureIndex importedSignatureIndex = importedExport->signatureIndex();
Wasm::SignatureIndex expectedSignatureIndex = moduleInformation.importFunctionSignatureIndices[import.kindIndex];
if (importedSignatureIndex != expectedSignatureIndex)
return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("imported function's signature doesn't match the provided WebAssembly function's signature"))));
// b. Let closure be v.[[Closure]].
}
// iii. Otherwise:
// a. Let closure be a new host function of the given signature which calls v by coercing WebAssembly arguments to JavaScript arguments via ToJSValue and returns the result, if any, by coercing via ToWebAssemblyValue.
// Note: done as part of Plan compilation.
// iv. Append v to funcs.
// Note: adding the JSCell to the instance list fulfills closure requirements b. above (the WebAssembly.Instance wil be kept alive) and v. below (the JSFunction).
instance->setImportFunction(vm, cell, numImportFunctions++);
// v. Append closure to imports.
break;
}
case Wasm::ExternalKind::Table: {
RELEASE_ASSERT(!hasTableImport); // This should be guaranteed by a validation failure.
// 7. Otherwise (i is a table import):
hasTableImport = true;
JSWebAssemblyTable* table = jsDynamicCast<JSWebAssemblyTable*>(vm, value);
// i. If v is not a WebAssembly.Table object, throw a WebAssembly.LinkError.
if (!table)
return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Table import is not an instance of WebAssembly.Table"))));
uint32_t expectedInitial = moduleInformation.tableInformation.initial();
uint32_t actualInitial = table->size();
if (actualInitial < expectedInitial)
return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Table import provided an 'initial' that is too small"))));
if (std::optional<uint32_t> expectedMaximum = moduleInformation.tableInformation.maximum()) {
std::optional<uint32_t> actualMaximum = table->maximum();
if (!actualMaximum) {
//.........这里部分代码省略.........