本文整理汇总了C++中JSValue::isUndefined方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isUndefined方法的具体用法?C++ JSValue::isUndefined怎么用?C++ JSValue::isUndefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::isUndefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showContextMenu
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* execState, const ArgList& args)
{
if (args.size() < 2)
return jsUndefined();
Event* event = toEvent(args.at(0));
JSArray* array = asArray(args.at(1));
Vector<ContextMenuItem*> items;
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(i));
JSValue label = item->get(execState, Identifier(execState, "label"));
JSValue id = item->get(execState, Identifier(execState, "id"));
if (label.isUndefined() || id.isUndefined())
items.append(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(execState));
items.append(new ContextMenuItem(ActionType, typedId, label.toString(execState)));
}
}
impl()->showContextMenu(event, items);
return jsUndefined();
}
示例2: populateContextMenuItems
static void populateContextMenuItems(ExecState* exec, JSArray* array, ContextMenu& menu)
{
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(exec, i));
JSValue label = item->get(exec, Identifier::fromString(exec, "label"));
JSValue type = item->get(exec, Identifier::fromString(exec, "type"));
JSValue id = item->get(exec, Identifier::fromString(exec, "id"));
JSValue enabled = item->get(exec, Identifier::fromString(exec, "enabled"));
JSValue checked = item->get(exec, Identifier::fromString(exec, "checked"));
JSValue subItems = item->get(exec, Identifier::fromString(exec, "subItems"));
if (!type.isString())
continue;
String typeString = type.toWTFString(exec);
if (typeString == "separator") {
ContextMenuItem item(SeparatorType, ContextMenuItemTagNoAction, String());
menu.appendItem(item);
} else if (typeString == "subMenu" && subItems.inherits(JSArray::info())) {
ContextMenu subMenu;
JSArray* subItemsArray = asArray(subItems);
populateContextMenuItems(exec, subItemsArray, subMenu);
ContextMenuItem item(SubmenuType, ContextMenuItemTagNoAction, label.toWTFString(exec), &subMenu);
menu.appendItem(item);
} else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, label.toWTFString(exec));
if (!enabled.isUndefined())
menuItem.setEnabled(enabled.toBoolean(exec));
if (!checked.isUndefined())
menuItem.setChecked(checked.toBoolean(exec));
menu.appendItem(menuItem);
}
}
}
示例3: errorProtoFuncToString
// ECMA-262 5.1, 15.11.4.4
EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 1. Let O be the this value.
JSValue thisValue = exec->thisValue();
// 2. If Type(O) is not Object, throw a TypeError exception.
if (!thisValue.isObject())
return throwVMTypeError(exec, scope);
JSObject* thisObj = asObject(thisValue);
// Guard against recursion!
StringRecursionChecker checker(exec, thisObj);
ASSERT(!scope.exception() || checker.earlyReturnValue());
if (JSValue earlyReturnValue = checker.earlyReturnValue())
return JSValue::encode(earlyReturnValue);
// 3. Let name be the result of calling the [[Get]] internal method of O with argument "name".
JSValue name = thisObj->get(exec, exec->propertyNames().name);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
// 4. If name is undefined, then let name be "Error"; else let name be ToString(name).
String nameString;
if (name.isUndefined())
nameString = ASCIILiteral("Error");
else {
nameString = name.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
// 5. Let msg be the result of calling the [[Get]] internal method of O with argument "message".
JSValue message = thisObj->get(exec, exec->propertyNames().message);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
// (sic)
// 6. If msg is undefined, then let msg be the empty String; else let msg be ToString(msg).
// 7. If msg is undefined, then let msg be the empty String; else let msg be ToString(msg).
String messageString;
if (message.isUndefined())
messageString = String();
else {
messageString = message.toWTFString(exec);
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
// 8. If name is the empty String, return msg.
if (!nameString.length())
return JSValue::encode(message.isString() ? message : jsString(exec, messageString));
// 9. If msg is the empty String, return name.
if (!messageString.length())
return JSValue::encode(name.isString() ? name : jsString(exec, nameString));
// 10. Return the result of concatenating name, ":", a single space character, and msg.
scope.release();
return JSValue::encode(jsMakeNontrivialString(exec, nameString, ": ", messageString));
}
示例4: throwTypeError
template<> DictionaryImplName convertDictionary<DictionaryImplName>(ExecState& state, JSValue value)
{
VM& vm = state.vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
bool isNullOrUndefined = value.isUndefinedOrNull();
auto* object = isNullOrUndefined ? nullptr : value.getObject();
if (UNLIKELY(!isNullOrUndefined && !object)) {
throwTypeError(&state, throwScope);
return { };
}
DictionaryImplName result;
JSValue boolMemberValue;
if (isNullOrUndefined)
boolMemberValue = jsUndefined();
else {
boolMemberValue = object->get(&state, Identifier::fromString(&state, "boolMember"));
RETURN_IF_EXCEPTION(throwScope, { });
}
if (!boolMemberValue.isUndefined()) {
result.boolMember = convert<IDLBoolean>(state, boolMemberValue);
RETURN_IF_EXCEPTION(throwScope, { });
}
JSValue callbackMemberValue;
if (isNullOrUndefined)
callbackMemberValue = jsUndefined();
else {
callbackMemberValue = object->get(&state, Identifier::fromString(&state, "callbackMember"));
RETURN_IF_EXCEPTION(throwScope, { });
}
if (!callbackMemberValue.isUndefined()) {
result.callbackMember = convert<IDLCallbackFunction<JSVoidCallback>>(state, callbackMemberValue, *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject()));
RETURN_IF_EXCEPTION(throwScope, { });
}
JSValue enumMemberValue;
if (isNullOrUndefined)
enumMemberValue = jsUndefined();
else {
enumMemberValue = object->get(&state, Identifier::fromString(&state, "enumMember"));
RETURN_IF_EXCEPTION(throwScope, { });
}
if (!enumMemberValue.isUndefined()) {
result.enumMember = convert<IDLEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>>(state, enumMemberValue);
RETURN_IF_EXCEPTION(throwScope, { });
}
JSValue stringMemberValue;
if (isNullOrUndefined)
stringMemberValue = jsUndefined();
else {
stringMemberValue = object->get(&state, Identifier::fromString(&state, "stringMember"));
RETURN_IF_EXCEPTION(throwScope, { });
}
if (!stringMemberValue.isUndefined()) {
result.stringMember = convert<IDLDOMString>(state, stringMemberValue);
RETURN_IF_EXCEPTION(throwScope, { });
}
return result;
}
示例5: getBackref
JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i)
{
JSArray* array = m_cachedResult.lastResult(exec, this);
if (i < array->length()) {
JSValue result = JSValue(array).get(exec, i);
ASSERT(result.isString() || result.isUndefined());
if (!result.isUndefined())
return result;
}
return jsEmptyString(exec);
}
示例6: getLastParen
JSValue RegExpConstructor::getLastParen(ExecState* exec)
{
JSArray* array = m_cachedResult.lastResult(exec, this);
unsigned length = array->length();
if (length > 1) {
JSValue result = JSValue(array).get(exec, length - 1);
ASSERT(result.isString() || result.isUndefined());
if (!result.isUndefined())
return result;
}
return jsEmptyString(exec);
}
示例7: compareByStringForQSort
static int compareByStringForQSort(const void *a, const void *b)
{
ExecState *exec = execForCompareByStringForQSort;
JSValue *va = *(JSValue **)a;
JSValue *vb = *(JSValue **)b;
if (va->isUndefined()) {
return vb->isUndefined() ? 0 : 1;
}
if (vb->isUndefined()) {
return -1;
}
return compare(va->toString(exec), vb->toString(exec));
}
示例8: constructRegExp
JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, JSObject* callee, JSValue newTarget)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue patternArg = args.at(0);
JSValue flagsArg = args.at(1);
bool isPatternRegExp = patternArg.inherits(vm, RegExpObject::info());
bool constructAsRegexp = isRegExp(vm, exec, patternArg);
RETURN_IF_EXCEPTION(scope, nullptr);
if (newTarget.isUndefined() && constructAsRegexp && flagsArg.isUndefined()) {
JSValue constructor = patternArg.get(exec, vm.propertyNames->constructor);
RETURN_IF_EXCEPTION(scope, nullptr);
if (callee == constructor) {
// We know that patternArg is a object otherwise constructAsRegexp would be false.
return patternArg.getObject();
}
}
if (isPatternRegExp) {
RegExp* regExp = jsCast<RegExpObject*>(patternArg)->regExp();
Structure* structure = getRegExpStructure(exec, globalObject, newTarget);
RETURN_IF_EXCEPTION(scope, nullptr);
if (!flagsArg.isUndefined()) {
RegExpFlags flags = toFlags(exec, flagsArg);
ASSERT(!!scope.exception() == (flags == InvalidFlags));
if (flags == InvalidFlags)
return nullptr;
regExp = RegExp::create(vm, regExp->pattern(), flags);
}
return RegExpObject::create(vm, structure, regExp);
}
if (constructAsRegexp) {
JSValue pattern = patternArg.get(exec, vm.propertyNames->source);
RETURN_IF_EXCEPTION(scope, nullptr);
if (flagsArg.isUndefined()) {
flagsArg = patternArg.get(exec, vm.propertyNames->flags);
RETURN_IF_EXCEPTION(scope, nullptr);
}
patternArg = pattern;
}
scope.release();
return regExpCreate(exec, globalObject, newTarget, patternArg, flagsArg);
}
示例9: encode
static EncodedJSValue JSC_HOST_CALL callSymbol(ExecState* exec)
{
JSValue description = exec->argument(0);
if (description.isUndefined())
return JSValue::encode(Symbol::create(exec->vm()));
return JSValue::encode(Symbol::create(exec, description.toString(exec)));
}
示例10: encode
static EncodedJSValue JSC_HOST_CALL IntlDateTimeFormatFuncFormatDateTime(ExecState* state)
{
// 12.3.4 DateTime Format Functions (ECMA-402 2.0)
// 1. Let dtf be the this value.
// 2. Assert: Type(dtf) is Object and dtf has an [[initializedDateTimeFormat]] internal slot whose value is true.
IntlDateTimeFormat* format = jsCast<IntlDateTimeFormat*>(state->thisValue());
JSValue date = state->argument(0);
double value;
// 3. If date is not provided or is undefined, then
if (date.isUndefined()) {
// a. Let x be %Date_now%().
value = JSValue::decode(dateNow(state)).toNumber(state);
} else {
// 4. Else
// a. Let x be ToNumber(date).
value = date.toNumber(state);
// b. ReturnIfAbrupt(x).
if (state->hadException())
return JSValue::encode(jsUndefined());
}
// 5. Return FormatDateTime(dtf, x).
return JSValue::encode(format->format(*state, value));
}
示例11: normalizeHighWaterMark
static inline double normalizeHighWaterMark(ExecState& exec, JSObject& strategy)
{
JSValue jsHighWaterMark = getPropertyFromObject(exec, strategy, "highWaterMark");
if (exec.hadException())
return 0;
if (jsHighWaterMark.isUndefined())
return 1;
double highWaterMark = jsHighWaterMark.toNumber(&exec);
if (exec.hadException())
return 0;
if (std::isnan(highWaterMark)) {
throwVMError(&exec, createTypeError(&exec, ASCIILiteral("Value is NaN")));
return 0;
}
if (highWaterMark < 0) {
throwVMError(&exec, createRangeError(&exec, ASCIILiteral("Not a positive value")));
return 0;
}
return highWaterMark;
}
示例12: 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;
}
示例13: _NPN_HasMethod
bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o);
PrivateIdentifier* i = static_cast<PrivateIdentifier*>(methodName);
if (!i->isString)
return false;
RootObject* rootObject = obj->rootObject;
if (!rootObject || !rootObject->isValid())
return false;
ExecState* exec = rootObject->globalObject()->globalExec();
JSLock lock(false);
JSValue* func = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string));
exec->clearException();
return !func->isUndefined();
}
if (o->_class->hasMethod)
return o->_class->hasMethod(o, methodName);
return false;
}
示例14: injectIDBKeyIntoScriptValue
bool injectIDBKeyIntoScriptValue(JSC::ExecState& exec, const IDBKeyData& keyData, JSC::JSValue value, const IDBKeyPath& keyPath)
{
LOG(IndexedDB, "injectIDBKeyIntoScriptValue");
ASSERT(keyPath.type() == IndexedDB::KeyPathType::String);
Vector<String> keyPathElements;
IDBKeyPathParseError error;
IDBParseKeyPath(keyPath.string(), keyPathElements, error);
ASSERT(error == IDBKeyPathParseError::None);
if (keyPathElements.isEmpty())
return false;
JSValue parent = ensureNthValueOnKeyPath(&exec, value, keyPathElements, keyPathElements.size() - 1);
if (parent.isUndefined())
return false;
auto key = keyData.maybeCreateIDBKey();
if (!key)
return false;
if (!set(&exec, parent, keyPathElements.last(), idbKeyToJSValue(&exec, exec.lexicalGlobalObject(), key.get())))
return false;
return true;
}
示例15: _NPN_HasMethod
bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject* obj = (JavaScriptObject*)o;
if (!_isSafeScript(obj))
return false;
PrivateIdentifier* i = (PrivateIdentifier*)methodName;
if (!i->isString)
return false;
RootObject* rootObject = obj->rootObject;
if (!rootObject || !rootObject->isValid())
return false;
ExecState* exec = rootObject->interpreter()->globalExec();
JSLock lock;
JSValue* func = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string));
return !func->isUndefined();
}
if (o->_class->hasMethod)
return o->_class->hasMethod(o, methodName);
return false;
}