本文整理汇总了C++中JSValue::put方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::put方法的具体用法?C++ JSValue::put怎么用?C++ JSValue::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::put方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ident
ALWAYS_INLINE static void operationPutByValInternal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
{
JSGlobalData* globalData = &exec->globalData();
JSValue baseValue = JSValue::decode(encodedBase);
JSValue property = JSValue::decode(encodedProperty);
JSValue value = JSValue::decode(encodedValue);
if (LIKELY(property.isUInt32())) {
uint32_t i = property.asUInt32();
if (isJSArray(globalData, baseValue)) {
JSArray* jsArray = asArray(baseValue);
if (jsArray->canSetIndex(i)) {
jsArray->setIndex(*globalData, i, value);
return;
}
jsArray->JSArray::put(exec, i, value);
return;
}
if (isJSByteArray(globalData, baseValue) && asByteArray(baseValue)->canAccessIndex(i)) {
JSByteArray* jsByteArray = asByteArray(baseValue);
// FIXME: the JITstub used to relink this to an optimized form!
if (value.isInt32()) {
jsByteArray->setIndex(i, value.asInt32());
return;
}
double dValue = 0;
if (value.getNumber(dValue)) {
jsByteArray->setIndex(i, dValue);
return;
}
}
baseValue.put(exec, i, value);
return;
}
// Don't put to an object if toString throws an exception.
Identifier ident(exec, property.toString(exec));
if (!globalData->exception) {
PutPropertySlot slot(strict);
baseValue.put(exec, ident, value, slot);
}
}
示例2: tracer
ALWAYS_INLINE static void JIT_OPERATION operationPutByValInternal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
{
VM* vm = &exec->vm();
NativeCallFrameTracer tracer(vm, exec);
JSValue baseValue = JSValue::decode(encodedBase);
JSValue property = JSValue::decode(encodedProperty);
JSValue value = JSValue::decode(encodedValue);
if (LIKELY(property.isUInt32())) {
putByVal<strict, direct>(exec, baseValue, property.asUInt32(), value);
return;
}
if (property.isDouble()) {
double propertyAsDouble = property.asDouble();
uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
if (propertyAsDouble == propertyAsUInt32) {
putByVal<strict, direct>(exec, baseValue, propertyAsUInt32, value);
return;
}
}
// Don't put to an object if toString throws an exception.
PropertyName propertyName = property.toPropertyKey(exec);
if (!vm->exception()) {
PutPropertySlot slot(baseValue, strict);
if (direct) {
RELEASE_ASSERT(baseValue.isObject());
asObject(baseValue)->putDirect(*vm, propertyName, value, slot);
} else
baseValue.put(exec, propertyName, value, slot);
}
}
示例3: tracer
ALWAYS_INLINE static void JIT_OPERATION operationPutByValInternal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue)
{
VM* vm = &exec->vm();
NativeCallFrameTracer tracer(vm, exec);
JSValue baseValue = JSValue::decode(encodedBase);
JSValue property = JSValue::decode(encodedProperty);
JSValue value = JSValue::decode(encodedValue);
if (LIKELY(property.isUInt32())) {
// Despite its name, JSValue::isUInt32 will return true only for positive boxed int32_t; all those values are valid array indices.
ASSERT(isIndex(property.asUInt32()));
putByVal<strict, direct>(exec, baseValue, property.asUInt32(), value);
return;
}
if (property.isDouble()) {
double propertyAsDouble = property.asDouble();
uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
if (propertyAsDouble == propertyAsUInt32 && isIndex(propertyAsUInt32)) {
putByVal<strict, direct>(exec, baseValue, propertyAsUInt32, value);
return;
}
}
// Don't put to an object if toString throws an exception.
auto propertyName = property.toPropertyKey(exec);
if (vm->exception())
return;
PutPropertySlot slot(baseValue, strict);
if (direct) {
RELEASE_ASSERT(baseValue.isObject());
if (Optional<uint32_t> index = parseIndex(propertyName))
asObject(baseValue)->putDirectIndex(exec, index.value(), value, 0, strict ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
else
asObject(baseValue)->putDirect(*vm, propertyName, value, slot);
} else
baseValue.put(exec, propertyName, value, slot);
}
示例4: toJSON
JSC::JSValue JSClientRect::toJSON(ExecState& state)
{
ClientRect& rect = wrapped();
VM& vm = state.vm();
JSValue object = constructEmptyObject(&state);
CodeBlock* codeBlock = state.codeBlock();
PutPropertySlot slot(object, codeBlock ? codeBlock->isStrictMode() : false);
object.put(&state, Identifier::fromString(&vm, ASCIILiteral("top")), jsNumber(rect.top()), slot);
object.put(&state, Identifier::fromString(&vm, ASCIILiteral("right")), jsNumber(rect.right()), slot);
object.put(&state, Identifier::fromString(&vm, ASCIILiteral("bottom")), jsNumber(rect.bottom()), slot);
object.put(&state, Identifier::fromString(&vm, ASCIILiteral("left")), jsNumber(rect.left()), slot);
object.put(&state, Identifier::fromString(&vm, ASCIILiteral("width")), jsNumber(rect.width()), slot);
object.put(&state, Identifier::fromString(&vm, ASCIILiteral("height")), jsNumber(rect.height()), slot);
return object;
}