本文整理汇总了C++中jsc::JSValue::isString方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isString方法的具体用法?C++ JSValue::isString怎么用?C++ JSValue::isString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsc::JSValue
的用法示例。
在下文中一共展示了JSValue::isString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluate
JSC::JSValue ScriptModuleLoader::evaluate(JSC::JSGlobalObject*, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue moduleRecordValue, JSC::JSValue)
{
JSC::VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// FIXME: Currently, we only support JSModuleRecord.
// Once the reflective part of the module loader is supported, we will handle arbitrary values.
// https://whatwg.github.io/loader/#registry-prototype-provide
auto* moduleRecord = jsDynamicDowncast<JSC::JSModuleRecord*>(moduleRecordValue);
if (!moduleRecord)
return JSC::jsUndefined();
URL sourceURL;
if (moduleKeyValue.isSymbol())
sourceURL = m_document.url();
else if (moduleKeyValue.isString())
sourceURL = URL(URL(), asString(moduleKeyValue)->value(exec));
else
return JSC::throwTypeError(exec, scope, ASCIILiteral("Module key is not Symbol or String."));
if (!sourceURL.isValid())
return JSC::throwTypeError(exec, scope, ASCIILiteral("Module key is an invalid URL."));
if (auto* frame = m_document.frame())
return frame->script().evaluateModule(sourceURL, *moduleRecord);
return JSC::jsUndefined();
}
示例2: asURL
String DragData::asURL(String* /*title*/) const
{
JSC::JSLock lock(false);
bool success;
JSC::JSValue data = m_platformDragData->getData(ClipboardApolloHelper::URI_LIST_TYPE, success);
if (success && data.isString())
return String(ustringToString(data.toString(m_platformDragData->execState())));
return String();
}
示例3: create
PassRefPtr<IDBKey> createIDBKeyFromValue(JSC::ExecState* exec, JSC::JSValue value)
{
if (value.isNull())
return IDBKey::create();
if (value.isInt32())
return IDBKey::create(value.toInt32(exec));
if (value.isString())
return IDBKey::create(ustringToString(value.toString(exec)));
// FIXME: Implement dates.
return 0;
}
示例4: if
ExceptionOr<Ref<FontFace>> FontFace::create(JSC::ExecState& state, Document& document, const String& family, JSC::JSValue source, const Descriptors& descriptors)
{
auto result = adoptRef(*new FontFace(document.fontSelector()));
bool dataRequiresAsynchronousLoading = true;
auto setFamilyResult = result->setFamily(family);
if (setFamilyResult.hasException())
return setFamilyResult.releaseException();
if (source.isString()) {
auto value = FontFace::parseString(source.getString(&state), CSSPropertySrc);
if (!is<CSSValueList>(value.get()))
return Exception { SYNTAX_ERR };
CSSFontFace::appendSources(result->backing(), downcast<CSSValueList>(*value), &document, false);
} else if (auto arrayBufferView = toUnsharedArrayBufferView(source))
dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull());
else if (auto arrayBuffer = toUnsharedArrayBuffer(source)) {
auto arrayBufferView = JSC::Uint8Array::create(arrayBuffer, 0, arrayBuffer->byteLength());
dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull());
}
// These ternaries match the default strings inside the FontFaceDescriptors dictionary inside FontFace.idl.
auto setStyleResult = result->setStyle(descriptors.style.isEmpty() ? ASCIILiteral("normal") : descriptors.style);
if (setStyleResult.hasException())
return setStyleResult.releaseException();
auto setWeightResult = result->setWeight(descriptors.weight.isEmpty() ? ASCIILiteral("normal") : descriptors.weight);
if (setWeightResult.hasException())
return setWeightResult.releaseException();
auto setStretchResult = result->setStretch(descriptors.stretch.isEmpty() ? ASCIILiteral("normal") : descriptors.stretch);
if (setStretchResult.hasException())
return setStretchResult.releaseException();
auto setUnicodeRangeResult = result->setUnicodeRange(descriptors.unicodeRange.isEmpty() ? ASCIILiteral("U+0-10FFFF") : descriptors.unicodeRange);
if (setUnicodeRangeResult.hasException())
return setUnicodeRangeResult.releaseException();
auto setVariantResult = result->setVariant(descriptors.variant.isEmpty() ? ASCIILiteral("normal") : descriptors.variant);
if (setVariantResult.hasException())
return setVariantResult.releaseException();
auto setFeatureSettingsResult = result->setFeatureSettings(descriptors.featureSettings.isEmpty() ? ASCIILiteral("normal") : descriptors.featureSettings);
if (setFeatureSettingsResult.hasException())
return setFeatureSettingsResult.releaseException();
if (!dataRequiresAsynchronousLoading) {
result->backing().load();
ASSERT(result->backing().status() == CSSFontFace::Status::Success);
}
return WTFMove(result);
}
示例5: JSValueGetType
JSType JSValueGetType(JSContextRef, JSValueRef value)
{
JSC::JSValue* jsValue = toJS(value);
if (jsValue->isUndefined())
return kJSTypeUndefined;
if (jsValue->isNull())
return kJSTypeNull;
if (jsValue->isBoolean())
return kJSTypeBoolean;
if (jsValue->isNumber())
return kJSTypeNumber;
if (jsValue->isString())
return kJSTypeString;
ASSERT(jsValue->isObject());
return kJSTypeObject;
}
示例6: JSValueGetType
JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
{
JSC::ExecState* exec = toJS(ctx);
exec->globalData().heap.registerThread();
JSC::JSLock lock(exec);
JSC::JSValue jsValue = toJS(exec, value);
if (jsValue.isUndefined())
return kJSTypeUndefined;
if (jsValue.isNull())
return kJSTypeNull;
if (jsValue.isBoolean())
return kJSTypeBoolean;
if (jsValue.isNumber())
return kJSTypeNumber;
if (jsValue.isString())
return kJSTypeString;
ASSERT(jsValue.isObject());
return kJSTypeObject;
}
示例7: stringByEvaluatingJavaScriptInScriptWorld
bool WebFrame::stringByEvaluatingJavaScriptInScriptWorld(WebScriptWorld* world, void* jsGlobalObject, const char* script, const char** evaluationResult)
{
if (!world || !jsGlobalObject || !evaluationResult)
return false;
*evaluationResult = 0;
Frame* coreFrame = core(this);
JSObjectRef globalObjectRef = reinterpret_cast<JSObjectRef>(jsGlobalObject);
String string = String(script);
// Start off with some guess at a frame and a global object, we'll try to do better...!
JSDOMWindow* anyWorldGlobalObject = coreFrame->script()->globalObject(mainThreadNormalWorld());
// The global object is probably a shell object? - if so, we know how to use this!
JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell"))
anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window();
// Get the frame from the global object we've settled on.
Frame* frame = anyWorldGlobalObject->impl()->frame();
ASSERT(frame->document());
JSC::JSValue result = frame->script()->executeScriptInWorld(world->world(), string, true).jsValue();
if (!frame) // In case the script removed our frame from the page.
return true;
// This bizarre set of rules matches behavior from WebKit for Safari 2.0.
// If you don't like it, use -[WebScriptObject evaluateWebScript:] or
// JSEvaluateScript instead, since they have less surprising semantics.
if (!result || !result.isBoolean() && !result.isString() && !result.isNumber())
return true;
JSC::JSLock lock(JSC::SilenceAssertionsOnly);
String resultString = ustringToString(result.toString(anyWorldGlobalObject->globalExec()));
*evaluationResult = strdup(resultString.utf8().data());
return true;
}
示例8: asPlainText
String DragData::asPlainText() const
{
JSC::JSLock lock(false);
bool success;
JSC::JSValue data = m_platformDragData->getData(ClipboardApolloHelper::TEXT_TYPE, success);
if (success && data.isString())
return String(ustringToString(data.toString(m_platformDragData->execState())));
Vector<String> filenames;
asFilenames(filenames);
if (!filenames.isEmpty()) {
String result;
for (unsigned int i=0; i<filenames.size(); i++)
result.append(filenames[i] + "\n");
return result;
}
String url(asURL(NULL));
if (!url.isEmpty())
return url;
return String();
}
示例9: asFilenames
void DragData::asFilenames(Vector<String>& result) const
{
bool success;
JSC::JSValue data = m_platformDragData->getData(ClipboardApolloHelper::FILE_LIST_TYPE, success);
JSC::ExecState *exec = m_platformDragData->execState();
if (success && data.isObject()) {
JSC::JSObject* filenameArray = data.toObject(exec);
uint32_t length = filenameArray->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec);
for (uint32_t i=0; i<length; i++) {
JSC::JSValue fileValue = filenameArray->get(exec, i);
if (fileValue.isObject()) {
JSC::JSObject* file = fileValue.toObject(exec);
JSC::JSValue pathValue = file->get(exec, JSC::Identifier(exec, "nativePath"));
if (pathValue.isString()) {
String path = ustringToString(pathValue.toString(exec));
result.append(path);
}
}
}
}
if (exec->hadException())
exec->clearException();
}
示例10: evaluate
JSC::JSValue JSModuleLoader::evaluate(JSC::JSGlobalObject*, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue moduleRecordValue)
{
// FIXME: Currently, we only support JSModuleRecord.
// Once the reflective part of the module loader is supported, we will handle arbitrary values.
// https://whatwg.github.io/loader/#registry-prototype-provide
JSC::JSModuleRecord* moduleRecord = JSC::jsDynamicCast<JSC::JSModuleRecord*>(moduleRecordValue);
if (!moduleRecord)
return JSC::jsUndefined();
URL sourceUrl;
if (moduleKeyValue.isSymbol())
sourceUrl = m_document.url();
else if (moduleKeyValue.isString())
sourceUrl = URL(URL(), asString(moduleKeyValue)->value(exec));
else
return JSC::throwTypeError(exec, ASCIILiteral("Module key is not Symbol or String."));
if (!sourceUrl.isValid())
return JSC::throwTypeError(exec, ASCIILiteral("Module key is an invalid URL."));
// FIXME: Implement evaluating module code.
return JSC::jsUndefined();
}