本文整理汇总了C++中JSValue::get方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::get方法的具体用法?C++ JSValue::get怎么用?C++ JSValue::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: functionProtoFuncBind
// 15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, ...]])
EncodedJSValue JSC_HOST_CALL functionProtoFuncBind(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSGlobalObject* globalObject = exec->callee()->globalObject();
// Let Target be the this value.
JSValue target = exec->thisValue();
// If IsCallable(Target) is false, throw a TypeError exception.
CallData callData;
CallType callType = getCallData(target, callData);
if (callType == CallType::None)
return throwVMTypeError(exec, scope);
// Primitive values are not callable.
ASSERT(target.isObject());
JSObject* targetObject = asObject(target);
// Let A be a new (possibly empty) internal list of all of the argument values provided after thisArg (arg1, arg2 etc), in order.
size_t numBoundArgs = exec->argumentCount() > 1 ? exec->argumentCount() - 1 : 0;
JSArray* boundArgs;
if (numBoundArgs) {
boundArgs = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), numBoundArgs);
if (!boundArgs)
return JSValue::encode(throwOutOfMemoryError(exec, scope));
for (size_t i = 0; i < numBoundArgs; ++i)
boundArgs->initializeIndex(vm, i, exec->argument(i + 1));
} else
boundArgs = nullptr;
// If the [[Class]] internal property of Target is "Function", then ...
// Else set the length own property of F to 0.
unsigned length = 0;
if (targetObject->hasOwnProperty(exec, exec->propertyNames().length)) {
if (exec->hadException())
return JSValue::encode(jsUndefined());
// a. Let L be the length property of Target minus the length of A.
// b. Set the length own property of F to either 0 or L, whichever is larger.
JSValue lengthValue = target.get(exec, exec->propertyNames().length);
if (lengthValue.isNumber()) {
unsigned targetLength = (unsigned)lengthValue.asNumber();
if (targetLength > numBoundArgs)
length = targetLength - numBoundArgs;
}
}
JSValue nameProp = target.get(exec, exec->propertyNames().name);
JSString* name = nameProp.isString() ? nameProp.toString(exec) : jsEmptyString(exec);
return JSValue::encode(JSBoundFunction::create(vm, exec, globalObject, targetObject, exec->argument(0), boundArgs, length, name->value(exec)));
}
示例2: 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);
}
示例3: jsUndefined
static JSValue JSC_HOST_CALL callRuntimeMethod(ExecState* exec, JSObject* function, JSValue thisValue, const ArgList& args)
{
RuntimeMethod* method = static_cast<RuntimeMethod*>(function);
if (method->methods()->isEmpty())
return jsUndefined();
RuntimeObjectImp* imp;
if (thisValue.isObject(&RuntimeObjectImp::s_info)) {
imp = static_cast<RuntimeObjectImp*>(asObject(thisValue));
} else {
// If thisObj is the DOM object for a plugin, get the corresponding
// runtime object from the DOM object.
JSValue value = thisValue.get(exec, Identifier(exec, "__apple_runtime_object"));
if (value.isObject(&RuntimeObjectImp::s_info))
imp = static_cast<RuntimeObjectImp*>(asObject(value));
else
return throwError(exec, TypeError);
}
RefPtr<Instance> instance = imp->getInternalInstance();
if (!instance)
return RuntimeObjectImp::throwInvalidAccessError(exec);
instance->begin();
JSValue result = instance->invokeMethod(exec, *method->methods(), args);
instance->end();
return result;
}
示例4: iteratorForIterable
JSValue iteratorForIterable(ExecState* state, JSValue iterable)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue iteratorFunction = iterable.get(state, state->propertyNames().iteratorSymbol);
RETURN_IF_EXCEPTION(scope, JSValue());
CallData iteratorFunctionCallData;
CallType iteratorFunctionCallType = getCallData(iteratorFunction, iteratorFunctionCallData);
if (iteratorFunctionCallType == CallType::None) {
throwTypeError(state, scope);
return JSValue();
}
ArgList iteratorFunctionArguments;
JSValue iterator = call(state, iteratorFunction, iteratorFunctionCallType, iteratorFunctionCallData, iterable, iteratorFunctionArguments);
RETURN_IF_EXCEPTION(scope, JSValue());
if (!iterator.isObject()) {
throwTypeError(state, scope);
return JSValue();
}
return iterator;
}
示例5: operationGetByVal
EncodedJSValue DFG_OPERATION operationGetByVal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty)
{
JSGlobalData* globalData = &exec->globalData();
NativeCallFrameTracer tracer(globalData, exec);
JSValue baseValue = JSValue::decode(encodedBase);
JSValue property = JSValue::decode(encodedProperty);
if (LIKELY(baseValue.isCell())) {
JSCell* base = baseValue.asCell();
if (property.isUInt32()) {
return getByVal(exec, base, property.asUInt32());
} else if (property.isDouble()) {
double propertyAsDouble = property.asDouble();
uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble);
if (propertyAsUInt32 == propertyAsDouble)
return getByVal(exec, base, propertyAsUInt32);
} else if (property.isString()) {
if (JSValue result = base->fastGetOwnProperty(exec, asString(property)->value(exec)))
return JSValue::encode(result);
}
}
Identifier ident(exec, property.toString(exec)->value(exec));
return JSValue::encode(baseValue.get(exec, ident));
}
示例6: updateDeferredFromPotentialThenable
ThenableStatus updateDeferredFromPotentialThenable(ExecState* exec, JSValue x, JSPromiseDeferred* deferred)
{
// 1. If Type(x) is not Object, return "not a thenable".
if (!x.isObject())
return NotAThenable;
// 2. Let 'then' be the result of calling Get(x, "then").
JSValue thenValue = x.get(exec, exec->vm().propertyNames->then);
// 3. If then is an abrupt completion,
if (exec->hadException()) {
// i. Let 'rejectResult' be the result of calling the [[Call]] internal method of
// deferred.[[Reject]] with undefined as thisArgument and a List containing
// then.[[value]] as argumentsList.
JSValue exception = exec->exception();
exec->clearException();
performDeferredReject(exec, deferred, exception);
// ii. ReturnIfAbrupt(rejectResult).
// NOTE: Nothing to do.
// iii. Return.
return WasAThenable;
}
// 4. Let 'then' be then.[[value]].
// Note: Nothing to do.
// 5. If IsCallable(then) is false, return "not a thenable".
CallData thenCallData;
CallType thenCallType = getCallData(thenValue, thenCallData);
if (thenCallType == CallTypeNone)
return NotAThenable;
// 6. Let 'thenCallResult' be the result of calling the [[Call]] internal method of
// 'then' passing x as thisArgument and a List containing deferred.[[Resolve]] and
// deferred.[[Reject]] as argumentsList.
MarkedArgumentBuffer thenArguments;
thenArguments.append(deferred->resolve());
thenArguments.append(deferred->reject());
call(exec, thenValue, thenCallType, thenCallData, x, thenArguments);
// 7. If 'thenCallResult' is an abrupt completion,
if (exec->hadException()) {
// i. Let 'rejectResult' be the result of calling the [[Call]] internal method of
// deferred.[[Reject]] with undefined as thisArgument and a List containing
// thenCallResult.[[value]] as argumentsList.
JSValue exception = exec->exception();
exec->clearException();
performDeferredReject(exec, deferred, exception);
// ii. ReturnIfAbrupt(rejectResult).
// NOTE: Nothing to do.
}
return WasAThenable;
}
示例7: iteratorForIterable
IterationRecord iteratorForIterable(ExecState* state, JSValue iterable)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue iteratorFunction = iterable.get(state, vm.propertyNames->iteratorSymbol);
RETURN_IF_EXCEPTION(scope, { });
CallData iteratorFunctionCallData;
CallType iteratorFunctionCallType = getCallData(vm, iteratorFunction, iteratorFunctionCallData);
if (iteratorFunctionCallType == CallType::None) {
throwTypeError(state, scope);
return { };
}
ArgList iteratorFunctionArguments;
JSValue iterator = call(state, iteratorFunction, iteratorFunctionCallType, iteratorFunctionCallData, iterable, iteratorFunctionArguments);
RETURN_IF_EXCEPTION(scope, { });
if (!iterator.isObject()) {
throwTypeError(state, scope);
return { };
}
JSValue nextMethod = iterator.getObject()->get(state, vm.propertyNames->next);
RETURN_IF_EXCEPTION(scope, { });
return { iterator, nextMethod };
}
示例8: encode
static EncodedJSValue JSC_HOST_CALL constructWeakSet(ExecState* exec)
{
JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject();
Structure* weakSetStructure = globalObject->weakSetStructure();
JSWeakSet* weakSet = JSWeakSet::create(exec, weakSetStructure);
JSValue iterable = exec->argument(0);
if (iterable.isUndefinedOrNull())
return JSValue::encode(weakSet);
JSValue adderFunction = weakSet->JSObject::get(exec, exec->propertyNames().add);
if (exec->hadException())
return JSValue::encode(jsUndefined());
CallData adderFunctionCallData;
CallType adderFunctionCallType = getCallData(adderFunction, adderFunctionCallData);
if (adderFunctionCallType == CallTypeNone)
return JSValue::encode(throwTypeError(exec));
JSValue iteratorFunction = iterable.get(exec, exec->propertyNames().iteratorSymbol);
if (exec->hadException())
return JSValue::encode(jsUndefined());
CallData iteratorFunctionCallData;
CallType iteratorFunctionCallType = getCallData(iteratorFunction, iteratorFunctionCallData);
if (iteratorFunctionCallType == CallTypeNone)
return JSValue::encode(throwTypeError(exec));
ArgList iteratorFunctionArguments;
JSValue iterator = call(exec, iteratorFunction, iteratorFunctionCallType, iteratorFunctionCallData, iterable, iteratorFunctionArguments);
if (exec->hadException())
return JSValue::encode(jsUndefined());
if (!iterator.isObject())
return JSValue::encode(throwTypeError(exec));
while (true) {
JSValue next = iteratorStep(exec, iterator);
if (exec->hadException())
return JSValue::encode(jsUndefined());
if (next.isFalse())
return JSValue::encode(weakSet);
JSValue nextValue = iteratorValue(exec, next);
if (exec->hadException())
return JSValue::encode(jsUndefined());
MarkedArgumentBuffer arguments;
arguments.append(nextValue);
call(exec, adderFunction, adderFunctionCallType, adderFunctionCallData, weakSet, arguments);
if (exec->hadException()) {
iteratorClose(exec, iterator);
return JSValue::encode(jsUndefined());
}
}
RELEASE_ASSERT_NOT_REACHED();
return JSValue::encode(weakSet);
}
示例9: hostResolveImportedModule
AbstractModuleRecord* AbstractModuleRecord::hostResolveImportedModule(ExecState* exec, const Identifier& moduleName)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue moduleNameValue = identifierToJSValue(vm, moduleName);
JSValue entry = m_dependenciesMap->JSMap::get(exec, moduleNameValue);
RETURN_IF_EXCEPTION(scope, nullptr);
RELEASE_AND_RETURN(scope, jsCast<AbstractModuleRecord*>(entry.get(exec, Identifier::fromString(exec, "module"))));
}
示例10: operationGetById
EncodedJSValue DFG_OPERATION operationGetById(ExecState* exec, EncodedJSValue base, Identifier* propertyName)
{
JSGlobalData* globalData = &exec->globalData();
NativeCallFrameTracer tracer(globalData, exec);
JSValue baseValue = JSValue::decode(base);
PropertySlot slot(baseValue);
return JSValue::encode(baseValue.get(exec, *propertyName, slot));
}
示例11: functionProtoFuncBind
// 15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, ...]])
EncodedJSValue JSC_HOST_CALL functionProtoFuncBind(ExecState* exec)
{
JSGlobalObject* globalObject = exec->callee()->globalObject();
// Let Target be the this value.
JSValue target = exec->hostThisValue();
// If IsCallable(Target) is false, throw a TypeError exception.
CallData callData;
CallType callType = getCallData(target, callData);
if (callType == CallTypeNone)
return throwVMTypeError(exec);
// Primitive values are not callable.
ASSERT(target.isObject());
JSObject* targetObject = asObject(target);
// Let A be a new (possibly empty) internal list of all of the argument values provided after thisArg (arg1, arg2 etc), in order.
size_t numBoundArgs = exec->argumentCount() > 1 ? exec->argumentCount() - 1 : 0;
JSArray* boundArgs = JSArray::tryCreateUninitialized(exec->globalData(), globalObject->arrayStructure(), numBoundArgs);
if (!boundArgs)
return JSValue::encode(throwOutOfMemoryError(exec));
for (size_t i = 0; i < numBoundArgs; ++i)
boundArgs->initializeIndex(exec->globalData(), i, exec->argument(i + 1));
boundArgs->completeInitialization(numBoundArgs);
// If the [[Class]] internal property of Target is "Function", then ...
// Else set the length own property of F to 0.
unsigned length = 0;
if (targetObject->inherits(&JSFunction::s_info)) {
ASSERT(target.get(exec, exec->propertyNames().length).isNumber());
// a. Let L be the length property of Target minus the length of A.
// b. Set the length own property of F to either 0 or L, whichever is larger.
unsigned targetLength = (unsigned)target.get(exec, exec->propertyNames().length).asNumber();
if (targetLength > numBoundArgs)
length = targetLength - numBoundArgs;
}
Identifier name(exec, target.get(exec, exec->propertyNames().name).toString(exec)->value(exec));
return JSValue::encode(JSBoundFunction::create(exec, globalObject, targetObject, exec->argument(0), boundArgs, length, name));
}
示例12: operationGetByIdProtoBuildListWithReturnAddress
EncodedJSValue DFG_OPERATION operationGetByIdProtoBuildListWithReturnAddress(ExecState* exec, EncodedJSValue base, Identifier* propertyName, ReturnAddressPtr returnAddress)
{
JSValue baseValue = JSValue::decode(base);
PropertySlot slot(baseValue);
JSValue result = baseValue.get(exec, *propertyName, slot);
StructureStubInfo& stubInfo = exec->codeBlock()->getStubInfo(returnAddress);
dfgBuildGetByIDProtoList(exec, baseValue, *propertyName, slot, stubInfo);
return JSValue::encode(result);
}
示例13: if
static std::error_code loadAction(ExecState& exec, const JSObject& ruleObject, Action& action, bool& validSelector)
{
VM& vm = exec.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
validSelector = true;
const JSValue actionObject = ruleObject.get(&exec, Identifier::fromString(&exec, "action"));
if (!actionObject || scope.exception() || !actionObject.isObject())
return ContentExtensionError::JSONInvalidAction;
const JSValue typeObject = actionObject.get(&exec, Identifier::fromString(&exec, "type"));
if (!typeObject || scope.exception() || !typeObject.isString())
return ContentExtensionError::JSONInvalidActionType;
String actionType = typeObject.toWTFString(&exec);
if (actionType == "block")
action = ActionType::BlockLoad;
else if (actionType == "ignore-previous-rules")
action = ActionType::IgnorePreviousRules;
else if (actionType == "block-cookies")
action = ActionType::BlockCookies;
else if (actionType == "css-display-none") {
JSValue selector = actionObject.get(&exec, Identifier::fromString(&exec, "selector"));
if (!selector || scope.exception() || !selector.isString())
return ContentExtensionError::JSONInvalidCSSDisplayNoneActionType;
String s = selector.toWTFString(&exec);
if (!isValidSelector(s)) {
// Skip rules with invalid selectors to be backwards-compatible.
validSelector = false;
return { };
}
action = Action(ActionType::CSSDisplayNoneSelector, s);
} else if (actionType == "make-https") {
action = ActionType::MakeHTTPS;
} else
return ContentExtensionError::JSONInvalidActionType;
return { };
}
示例14: createIndex
JSValue JSIDBObjectStore::createIndex(ExecState* exec)
{
ScriptExecutionContext* context = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
if (!context)
return exec->vm().throwException(exec, createReferenceError(exec, "IDBObjectStore script execution context is unavailable"));
if (exec->argumentCount() < 2)
return exec->vm().throwException(exec, createNotEnoughArgumentsError(exec));
String name = exec->argument(0).toString(exec)->value(exec);
if (exec->hadException())
return jsUndefined();
IDBKeyPath keyPath = idbKeyPathFromValue(exec, exec->argument(1));
if (exec->hadException())
return jsUndefined();
JSValue optionsValue = exec->argument(2);
if (!optionsValue.isUndefinedOrNull() && !optionsValue.isObject())
return throwTypeError(exec, "Not an object.");
bool unique = false;
bool multiEntry = false;
if (!optionsValue.isUndefinedOrNull()) {
unique = optionsValue.get(exec, Identifier(exec, "unique")).toBoolean(exec);
if (exec->hadException())
return jsUndefined();
multiEntry = optionsValue.get(exec, Identifier(exec, "multiEntry")).toBoolean(exec);
if (exec->hadException())
return jsUndefined();
}
ExceptionCode ec = 0;
JSValue result = toJS(exec, globalObject(), impl().createIndex(context, name, keyPath, unique, multiEntry, ec).get());
setDOMException(exec, ec);
return result;
}
示例15: operationGetByVal
EncodedJSValue operationGetByVal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty)
{
JSValue baseValue = JSValue::decode(encodedBase);
JSValue property = JSValue::decode(encodedProperty);
if (LIKELY(baseValue.isCell())) {
JSCell* base = baseValue.asCell();
if (property.isUInt32()) {
JSGlobalData* globalData = &exec->globalData();
uint32_t i = property.asUInt32();
// FIXME: the JIT used to handle these in compiled code!
if (isJSArray(globalData, base) && asArray(base)->canGetIndex(i))
return JSValue::encode(asArray(base)->getIndex(i));
// FIXME: the JITstub used to relink this to an optimized form!
if (isJSString(globalData, base) && asString(base)->canGetIndex(i))
return JSValue::encode(asString(base)->getIndex(exec, i));
// FIXME: the JITstub used to relink this to an optimized form!
if (isJSByteArray(globalData, base) && asByteArray(base)->canAccessIndex(i))
return JSValue::encode(asByteArray(base)->getIndex(exec, i));
return JSValue::encode(baseValue.get(exec, i));
}
if (property.isString()) {
Identifier propertyName(exec, asString(property)->value(exec));
PropertySlot slot(base);
if (base->fastGetOwnPropertySlot(exec, propertyName, slot))
return JSValue::encode(slot.getValue(exec, propertyName));
}
}
Identifier ident(exec, property.toString(exec));
return JSValue::encode(baseValue.get(exec, ident));
}