本文整理汇总了C++中JSValue::isNull方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::isNull方法的具体用法?C++ JSValue::isNull怎么用?C++ JSValue::isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::isNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encode
static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
{
VM& vm = exec->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
JSValue value = exec->argument(1);
WebAssemblyFunction* wasmFunction;
WebAssemblyWrapperFunction* wasmWrapperFunction;
if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction))
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, "WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function"_s)));
uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
if (index >= table->length())
return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, "WebAssembly.Table.prototype.set expects an integer less than the length of the table"_s)));
if (value.isNull())
table->clearFunction(index);
else {
ASSERT(value.isObject() && isWebAssemblyHostFunction(vm, jsCast<JSObject*>(value), wasmFunction, wasmWrapperFunction));
ASSERT(!!wasmFunction || !!wasmWrapperFunction);
if (wasmFunction)
table->setFunction(vm, index, wasmFunction);
else
table->setFunction(vm, index, wasmWrapperFunction);
}
return JSValue::encode(jsUndefined());
}
示例2: put
// ECMA 8.6.2.2
void JSObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
{
ASSERT(value);
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
if (propertyName == exec->propertyNames().underscoreProto) {
// Setting __proto__ to a non-object, non-null value is silently ignored to match Mozilla.
if (!value.isObject() && !value.isNull())
return;
if (!setPrototypeWithCycleCheck(value))
throwError(exec, createError(exec, "cyclic __proto__ value"));
return;
}
// Check if there are any setters or getters in the prototype chain
JSValue prototype;
for (JSObject* obj = this; !obj->structure()->hasGetterSetterProperties(); obj = asObject(prototype)) {
prototype = obj->prototype();
if (prototype.isNull()) {
putDirectInternal(exec->globalData(), propertyName, value, 0, true, slot);
return;
}
}
unsigned attributes;
JSCell* specificValue;
if ((m_structure->get(propertyName, attributes, specificValue) != WTF::notFound) && attributes & ReadOnly)
return;
for (JSObject* obj = this; ; obj = asObject(prototype)) {
if (JSValue gs = obj->getDirect(propertyName)) {
if (gs.isGetterSetter()) {
JSObject* setterFunc = asGetterSetter(gs)->setter();
if (!setterFunc) {
throwSetterError(exec);
return;
}
CallData callData;
CallType callType = setterFunc->getCallData(callData);
MarkedArgumentBuffer args;
args.append(value);
call(exec, setterFunc, callType, callData, this, args);
return;
}
// If there's an existing property on the object or one of its
// prototypes it should be replaced, so break here.
break;
}
prototype = obj->prototype();
if (prototype.isNull())
break;
}
putDirectInternal(exec->globalData(), propertyName, value, 0, true, slot);
return;
}
示例3: putToPrimitive
// ECMA 8.7.2
bool JSValue::putToPrimitive(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (Optional<uint32_t> index = parseIndex(propertyName))
return putToPrimitiveByIndex(exec, index.value(), value, slot.isStrictMode());
// Check if there are any setters or getters in the prototype chain
JSObject* obj = synthesizePrototype(exec);
if (UNLIKELY(!obj))
return false;
JSValue prototype;
if (propertyName != exec->propertyNames().underscoreProto) {
for (; !obj->structure()->hasReadOnlyOrGetterSetterPropertiesExcludingProto(); obj = asObject(prototype)) {
prototype = obj->getPrototypeDirect();
if (prototype.isNull()) {
if (slot.isStrictMode())
throwTypeError(exec, scope, StrictModeReadonlyPropertyWriteError);
return false;
}
}
}
for (; ; obj = asObject(prototype)) {
unsigned attributes;
PropertyOffset offset = obj->structure()->get(vm, propertyName, attributes);
if (offset != invalidOffset) {
if (attributes & ReadOnly) {
if (slot.isStrictMode())
throwTypeError(exec, scope, StrictModeReadonlyPropertyWriteError);
return false;
}
JSValue gs = obj->getDirect(offset);
if (gs.isGetterSetter())
return callSetter(exec, *this, gs, value, slot.isStrictMode() ? StrictMode : NotStrictMode);
if (gs.isCustomGetterSetter())
return callCustomSetter(exec, gs, attributes & CustomAccessor, obj, slot.thisValue(), value);
// If there's an existing property on the object or one of its
// prototypes it should be replaced, so break here.
break;
}
prototype = obj->getPrototype(vm, exec);
if (vm.exception())
return false;
if (prototype.isNull())
break;
}
if (slot.isStrictMode())
throwTypeError(exec, scope, StrictModeReadonlyPropertyWriteError);
return false;
}
示例4: prototypeChainMayInterceptStoreTo
bool Structure::prototypeChainMayInterceptStoreTo(JSGlobalData& globalData, PropertyName propertyName)
{
unsigned i = propertyName.asIndex();
if (i != PropertyName::NotAnIndex)
return anyObjectInChainMayInterceptIndexedAccesses();
for (Structure* current = this; ;) {
JSValue prototype = current->storedPrototype();
if (prototype.isNull())
return false;
current = prototype.asCell()->structure();
unsigned attributes;
JSCell* specificValue;
PropertyOffset offset = current->get(globalData, propertyName, attributes, specificValue);
if (!JSC::isValidOffset(offset))
continue;
if (attributes & (ReadOnly | Accessor))
return true;
return false;
}
}
示例5: atob
JSValue JSDOMWindow::atob(ExecState* exec, const ArgList& args)
{
if (args.size() < 1)
return throwError(exec, SyntaxError, "Not enough arguments");
JSValue v = args.at(0);
if (v.isNull())
return jsEmptyString(exec);
UString s = v.toString(exec);
if (!s.is8Bit()) {
setDOMException(exec, INVALID_CHARACTER_ERR);
return jsUndefined();
}
Vector<char> in(s.size());
for (int i = 0; i < s.size(); ++i)
in[i] = static_cast<char>(s.data()[i]);
Vector<char> out;
if (!base64Decode(in, out))
return throwError(exec, GeneralError, "Cannot decode base64");
return jsString(exec, String(out.data(), out.size()));
}
示例6: 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;
}
示例7: getEventListeners
JSValue JSCommandLineAPIHost::getEventListeners(ExecState& state)
{
if (state.argumentCount() < 1)
return jsUndefined();
JSValue value = state.uncheckedArgument(0);
if (!value.isObject() || value.isNull())
return jsUndefined();
Node* node = JSNode::toWrapped(value);
if (!node)
return jsUndefined();
Vector<EventListenerInfo> listenersArray;
wrapped().getEventListenersImpl(node, listenersArray);
JSObject* result = constructEmptyObject(&state);
for (size_t i = 0; i < listenersArray.size(); ++i) {
JSArray* listeners = getJSListenerFunctions(state, &node->document(), listenersArray[i]);
if (!listeners->length())
continue;
AtomicString eventType = listenersArray[i].eventType;
result->putDirect(state.vm(), Identifier::fromString(&state, eventType.impl()), JSValue(listeners));
}
return result;
}
示例8: dumpImmediate
void dumpImmediate(JSValue value)
{
if (value.isNull())
write(NullTag);
else if (value.isUndefined())
write(UndefinedTag);
else if (value.isNumber()) {
if (value.isInt32()) {
if (!value.asInt32())
write(ZeroTag);
else if (value.asInt32() == 1)
write(OneTag);
else {
write(IntTag);
write(static_cast<uint32_t>(value.asInt32()));
}
} else {
write(DoubleTag);
write(value.asDouble());
}
} else if (value.isBoolean()) {
if (value.isTrue())
write(TrueTag);
else
write(FalseTag);
}
}
示例9: getEventListeners
JSValue JSInjectedScriptHost::getEventListeners(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
JSValue value = exec->argument(0);
if (!value.isObject() || value.isNull())
return jsUndefined();
Node* node = toNode(value);
if (!node)
return jsUndefined();
// This can only happen for orphan DocumentType nodes.
Document* document = node->document();
if (!node->document())
return jsUndefined();
Vector<EventListenerInfo> listenersArray;
impl()->getEventListenersImpl(node, listenersArray);
JSObject* result = constructEmptyObject(exec);
for (size_t i = 0; i < listenersArray.size(); ++i) {
JSArray* listeners = getJSListenerFunctions(exec, document, listenersArray[i]);
if (!listeners->length())
continue;
AtomicString eventType = listenersArray[i].eventType;
result->putDirect(exec->globalData(), Identifier(exec, eventType.impl()), JSValue(listeners));
}
return result;
}
示例10: 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;
}
示例11: JSValueIsNull
bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
JSValue jsValue = toJS(exec, value);
return jsValue.isNull();
}
示例12: setDataSource
void JSHTMLDataGridElement::setDataSource(ExecState*, JSValue value)
{
if (value.isNull()) {
static_cast<HTMLDataGridElement*>(impl())->setDataSource(0);
return;
}
static_cast<HTMLDataGridElement*>(impl())->setDataSource(JSDataGridDataSource::create(value, impl()->document()->frame()));
}
示例13: JSValueIsNull
bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
{
ExecState* exec = toJS(ctx);
exec->globalData().heap.registerThread();
JSLock lock(exec);
JSValue jsValue = toJS(exec, value);
return jsValue.isNull();
}
示例14: result
std::unique_ptr<PolyProtoAccessChain> PolyProtoAccessChain::create(JSGlobalObject* globalObject, JSCell* base, JSObject* target, bool& usesPolyProto)
{
JSCell* current = base;
VM& vm = *base->vm();
bool found = false;
usesPolyProto = false;
std::unique_ptr<PolyProtoAccessChain> result(new PolyProtoAccessChain());
for (unsigned iterationNumber = 0; true; ++iterationNumber) {
Structure* structure = current->structure(vm);
if (!structure->propertyAccessesAreCacheable())
return nullptr;
if (structure->isProxy())
return nullptr;
if (structure->isDictionary()) {
ASSERT(structure->isObject());
if (structure->hasBeenFlattenedBefore())
return nullptr;
structure->flattenDictionaryStructure(vm, asObject(current));
}
// To save memory, we don't include the base in the chain. We let
// AccessCase provide the base to us as needed.
if (iterationNumber)
result->m_chain.append(structure);
else
RELEASE_ASSERT(current == base);
if (current == target) {
found = true;
break;
}
// We only have poly proto if we need to access our prototype via
// the poly proto protocol. If the slot base is the only poly proto
// thing in the chain, and we have a cache hit on it, then we're not
// poly proto.
usesPolyProto |= structure->hasPolyProto();
JSValue prototype = structure->prototypeForLookup(globalObject, current);
if (prototype.isNull())
break;
current = asObject(prototype);
}
if (!found && !!target)
return nullptr;
return result;
}
示例15:
IntendedStructureChain::IntendedStructureChain(JSGlobalObject* globalObject, Structure* head)
: m_globalObject(globalObject)
, m_head(head)
{
JSValue prototype = head->prototypeForLookup(globalObject);
if (prototype.isNull())
return;
for (Structure* current = asObject(prototype)->structure(); current; current = current->storedPrototypeStructure())
m_vector.append(current);
}