本文整理汇总了C++中JSArray类的典型用法代码示例。如果您正苦于以下问题:C++ JSArray类的具体用法?C++ JSArray怎么用?C++ JSArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: moduleLoaderPrototypeRequestedModules
EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeRequestedModules(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSModuleRecord* moduleRecord = jsDynamicCast<JSModuleRecord*>(vm, exec->argument(0));
if (!moduleRecord) {
scope.release();
return JSValue::encode(constructEmptyArray(exec, nullptr));
}
JSArray* result = constructEmptyArray(exec, nullptr, moduleRecord->requestedModules().size());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
size_t i = 0;
for (auto& key : moduleRecord->requestedModules()) {
result->putDirectIndex(exec, i++, jsString(exec, key.get()));
RETURN_IF_EXCEPTION(scope, encodedJSValue());
}
return JSValue::encode(result);
}
示例2: boundFunctionCall
EncodedJSValue JSC_HOST_CALL boundFunctionCall(ExecState* exec)
{
JSBoundFunction* boundFunction = jsCast<JSBoundFunction*>(exec->callee());
ASSERT(isJSArray(boundFunction->boundArgs())); // Currently this is true!
JSArray* boundArgs = asArray(boundFunction->boundArgs());
MarkedArgumentBuffer args;
for (unsigned i = 0; i < boundArgs->length(); ++i)
args.append(boundArgs->getIndex(i));
for (unsigned i = 0; i < exec->argumentCount(); ++i)
args.append(exec->argument(i));
JSObject* targetFunction = boundFunction->targetFunction();
CallData callData;
CallType callType = getCallData(targetFunction, callData);
ASSERT(callType != CallTypeNone);
return JSValue::encode(call(exec, targetFunction, callType, callData, boundFunction->boundThis(), args));
}
示例3: 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));
}
示例4: boundFunctionConstruct
EncodedJSValue JSC_HOST_CALL boundFunctionConstruct(ExecState* exec)
{
JSBoundFunction* boundFunction = jsCast<JSBoundFunction*>(exec->jsCallee());
JSArray* boundArgs = boundFunction->boundArgs();
MarkedArgumentBuffer args;
if (boundArgs) {
for (unsigned i = 0; i < boundArgs->length(); ++i)
args.append(boundArgs->getIndexQuickly(i));
}
for (unsigned i = 0; i < exec->argumentCount(); ++i)
args.append(exec->uncheckedArgument(i));
JSObject* targetFunction = boundFunction->targetFunction();
ConstructData constructData;
ConstructType constructType = getConstructData(targetFunction, constructData);
ASSERT(constructType != ConstructType::None);
return JSValue::encode(construct(exec, targetFunction, constructType, constructData, args));
}
示例5: promiseAllCountdownFunction
static EncodedJSValue JSC_HOST_CALL promiseAllCountdownFunction(ExecState* exec)
{
JSValue x = exec->argument(0);
VM& vm = exec->vm();
JSObject* F = exec->callee();
// 1. Let 'index' be the value of F's [[Index]] internal slot.
uint32_t index = F->get(exec, vm.propertyNames->indexPrivateName).asUInt32();
// 2. Let 'values' be the value of F's [[Values]] internal slot..
JSArray* values = jsCast<JSArray*>(F->get(exec, vm.propertyNames->valuesPrivateName));
// 3. Let 'deferred' be the value of F's [[Deferred]] internal slot.
JSPromiseDeferred* deferred = jsCast<JSPromiseDeferred*>(F->get(exec, vm.propertyNames->deferredPrivateName));
// 4. Let 'countdownHolder' be the value of F's [[CountdownHolder]] internal slot.
NumberObject* countdownHolder = jsCast<NumberObject*>(F->get(exec, vm.propertyNames->countdownHolderPrivateName));
// 5. Let 'result' be the result of calling the [[DefineOwnProperty]] internal method
// of 'values' with arguments 'index' and Property Descriptor { [[Value]]: x,
// [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
values->putDirectIndex(exec, index, x);
// 6. RejectIfAbrupt(result, deferred).
if (exec->hadException())
abruptRejection(exec, deferred);
// 7. Set countdownHolder.[[Countdown]] to countdownHolder.[[Countdown]] - 1.
uint32_t newCountdownValue = countdownHolder->internalValue().asUInt32() - 1;
countdownHolder->setInternalValue(vm, JSValue(newCountdownValue));
// 8. If countdownHolder.[[Countdown]] is 0,
if (!newCountdownValue) {
// i. Return the result of calling the [[Call]] internal method of deferred.[[Resolve]]
// with undefined as thisArgument and a List containing 'values' as argumentsList.
performDeferredResolve(exec, deferred, values);
}
// 9. Return.
return JSValue::encode(jsUndefined());
}
示例6: getJSListenerFunctions
static JSArray* getJSListenerFunctions(ExecState* exec, Document* document, const EventListenerInfo& listenerInfo)
{
JSArray* result = constructEmptyArray(exec);
size_t handlersCount = listenerInfo.eventListenerVector.size();
for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) {
const JSEventListener* jsListener = JSEventListener::cast(listenerInfo.eventListenerVector[i].listener.get());
if (!jsListener) {
ASSERT_NOT_REACHED();
continue;
}
// Hide listeners from other contexts.
if (jsListener->isolatedWorld() != currentWorld(exec))
continue;
JSObject* function = jsListener->jsFunction(document);
JSObject* listenerEntry = constructEmptyObject(exec);
listenerEntry->putDirect(exec->globalData(), Identifier(exec, "listener"), function);
listenerEntry->putDirect(exec->globalData(), Identifier(exec, "useCapture"), jsBoolean(listenerInfo.eventListenerVector[i].useCapture));
result->putDirectIndex(exec, outputIndex++, JSValue(listenerEntry));
}
return result;
}
示例7: createRegExpMatchesArray
JSArray* createRegExpMatchesArray(ExecState* exec, JSString* input, RegExp* regExp, MatchResult result)
{
ASSERT(result);
VM& vm = exec->vm();
JSArray* array = JSArray::tryCreateUninitialized(vm, exec->lexicalGlobalObject()->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), regExp->numSubpatterns() + 1);
RELEASE_ASSERT(array);
SamplingRegion samplingRegion("Reifying substring properties");
array->initializeIndex(vm, 0, jsSubstring(exec, input, result.start, result.end - result.start), ArrayWithContiguous);
if (unsigned numSubpatterns = regExp->numSubpatterns()) {
Vector<int, 32> subpatternResults;
int position = regExp->match(vm, input->value(exec), result.start, subpatternResults);
ASSERT_UNUSED(position, position >= 0 && static_cast<size_t>(position) == result.start);
ASSERT(result.start == static_cast<size_t>(subpatternResults[0]));
ASSERT(result.end == static_cast<size_t>(subpatternResults[1]));
for (unsigned i = 1; i <= numSubpatterns; ++i) {
int start = subpatternResults[2 * i];
if (start >= 0)
array->initializeIndex(vm, i, jsSubstring(exec, input, start, subpatternResults[2 * i + 1] - start), ArrayWithContiguous);
else
array->initializeIndex(vm, i, jsUndefined(), ArrayWithContiguous);
}
}
array->putDirect(vm, vm.propertyNames->index, jsNumber(result.start));
array->putDirect(vm, vm.propertyNames->input, input);
return array;
}
示例8: DECLARE_THROW_SCOPE
JSValue Database::toJS(ExecState* exec) const
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSObject* result = constructEmptyObject(exec);
JSArray* bytecodes = constructEmptyArray(exec, 0);
RETURN_IF_EXCEPTION(scope, JSValue());
for (unsigned i = 0; i < m_bytecodes.size(); ++i)
bytecodes->putDirectIndex(exec, i, m_bytecodes[i].toJS(exec));
result->putDirect(vm, exec->propertyNames().bytecodes, bytecodes);
JSArray* compilations = constructEmptyArray(exec, 0);
RETURN_IF_EXCEPTION(scope, JSValue());
for (unsigned i = 0; i < m_compilations.size(); ++i)
compilations->putDirectIndex(exec, i, m_compilations[i]->toJS(exec));
result->putDirect(vm, exec->propertyNames().compilations, compilations);
JSArray* events = constructEmptyArray(exec, 0);
RETURN_IF_EXCEPTION(scope, JSValue());
for (unsigned i = 0; i < m_events.size(); ++i)
events->putDirectIndex(exec, i, m_events[i].toJS(exec));
result->putDirect(vm, exec->propertyNames().events, events);
return result;
}
示例9: jsUndefined
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* exec)
{
if (exec->argumentCount() < 2)
return jsUndefined();
#if ENABLE(CONTEXT_MENUS)
Event* event = toEvent(exec->argument(0));
JSArray* array = asArray(exec->argument(1));
Vector<ContextMenuItem*> items;
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(i));
JSValue label = item->get(exec, Identifier(exec, "label"));
JSValue type = item->get(exec, Identifier(exec, "type"));
JSValue id = item->get(exec, Identifier(exec, "id"));
JSValue enabled = item->get(exec, Identifier(exec, "enabled"));
JSValue checked = item->get(exec, Identifier(exec, "checked"));
if (!type.isString())
continue;
String typeString = ustringToString(type.toString(exec)->value(exec));
if (typeString == "separator") {
items.append(new ContextMenuItem(SeparatorType,
ContextMenuItemCustomTagNoAction,
String()));
} else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
ContextMenuItem* menuItem = new ContextMenuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, ustringToString(label.toString(exec)->value(exec)));
if (!enabled.isUndefined())
menuItem->setEnabled(enabled.toBoolean(exec));
if (!checked.isUndefined())
menuItem->setChecked(checked.toBoolean(exec));
items.append(menuItem);
}
}
impl()->showContextMenu(event, items);
#endif
return jsUndefined();
}
示例10: throwVMError
EncodedJSValue JSC_HOST_CALL JSWebSocketConstructor::constructJSWebSocket(ExecState* exec)
{
JSWebSocketConstructor* jsConstructor = static_cast<JSWebSocketConstructor*>(exec->callee());
ScriptExecutionContext* context = jsConstructor->scriptExecutionContext();
if (!context)
return throwVMError(exec, createReferenceError(exec, "WebSocket constructor associated document is unavailable"));
if (!exec->argumentCount())
return throwVMError(exec, createSyntaxError(exec, "Not enough arguments"));
String urlString = ustringToString(exec->argument(0).toString(exec)->value(exec));
if (exec->hadException())
return throwVMError(exec, createSyntaxError(exec, "wrong URL"));
RefPtr<WebSocket> webSocket = WebSocket::create(context);
ExceptionCode ec = 0;
if (exec->argumentCount() < 2)
webSocket->connect(urlString, ec);
else {
JSValue protocolsValue = exec->argument(1);
if (isJSArray(protocolsValue)) {
Vector<String> protocols;
JSArray* protocolsArray = asArray(protocolsValue);
for (unsigned i = 0; i < protocolsArray->length(); ++i) {
String protocol = ustringToString(protocolsArray->getIndex(i).toString(exec)->value(exec));
if (exec->hadException())
return JSValue::encode(JSValue());
protocols.append(protocol);
}
webSocket->connect(urlString, protocols, ec);
} else {
String protocol = ustringToString(protocolsValue.toString(exec)->value(exec));
if (exec->hadException())
return JSValue::encode(JSValue());
webSocket->connect(urlString, protocol, ec);
}
}
setDOMException(exec, ec);
return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), WebSocket, webSocket.get()));
}
示例11: updateIndexingType
void ArrayAllocationProfile::updateIndexingType()
{
// This is awkwardly racy but totally sound even when executed concurrently. The
// worst cases go something like this:
//
// - Two threads race to execute this code; one of them succeeds in updating the
// m_currentIndexingType and the other either updates it again, or sees a null
// m_lastArray; if it updates it again then at worst it will cause the profile
// to "forget" some array. That's still sound, since we don't promise that
// this profile is a reflection of any kind of truth.
//
// - A concurrent thread reads m_lastArray, but that array is now dead. While
// it's possible for that array to no longer be reachable, it cannot actually
// be freed, since we require the GC to wait until all concurrent JITing
// finishes.
JSArray* lastArray = m_lastArray;
if (!lastArray)
return;
m_currentIndexingType = leastUpperBoundOfIndexingTypes(m_currentIndexingType, lastArray->structure()->indexingType());
m_lastArray = 0;
}
示例12: constructEmptyObject
JSValue Compilation::toJS(ExecState* exec) const
{
JSObject* result = constructEmptyObject(exec);
result->putDirect(exec->globalData(), exec->propertyNames().bytecodesID, jsNumber(m_bytecodes->id()));
result->putDirect(exec->globalData(), exec->propertyNames().compilationKind, jsString(exec, String::fromUTF8(toCString(m_kind))));
JSArray* profiledBytecodes = constructEmptyArray(exec, 0);
for (unsigned i = 0; i < m_profiledBytecodes.size(); ++i)
profiledBytecodes->putDirectIndex(exec, i, m_profiledBytecodes[i].toJS(exec));
result->putDirect(exec->globalData(), exec->propertyNames().profiledBytecodes, profiledBytecodes);
JSArray* descriptions = constructEmptyArray(exec, 0);
for (unsigned i = 0; i < m_descriptions.size(); ++i)
descriptions->putDirectIndex(exec, i, m_descriptions[i].toJS(exec));
result->putDirect(exec->globalData(), exec->propertyNames().descriptions, descriptions);
JSArray* counters = constructEmptyArray(exec, 0);
HashMap<OriginStack, OwnPtr<ExecutionCounter> >::const_iterator end = m_counters.end();
for (HashMap<OriginStack, OwnPtr<ExecutionCounter> >::const_iterator iter = m_counters.begin(); iter != end; ++iter) {
JSObject* counterEntry = constructEmptyObject(exec);
counterEntry->putDirect(exec->globalData(), exec->propertyNames().origin, iter->key.toJS(exec));
counterEntry->putDirect(exec->globalData(), exec->propertyNames().executionCount, jsNumber(iter->value->count()));
counters->push(exec, counterEntry);
}
result->putDirect(exec->globalData(), exec->propertyNames().counters, counters);
JSArray* exitSites = constructEmptyArray(exec, 0);
for (unsigned i = 0; i < m_osrExitSites.size(); ++i)
exitSites->putDirectIndex(exec, i, m_osrExitSites[i].toJS(exec));
result->putDirect(exec->globalData(), exec->propertyNames().osrExitSites, exitSites);
JSArray* exits = constructEmptyArray(exec, 0);
for (unsigned i = 0; i < m_osrExits.size(); ++i)
exits->putDirectIndex(exec, i, m_osrExits[i].toJS(exec));
result->putDirect(exec->globalData(), exec->propertyNames().osrExits, exits);
return result;
}
示例13: idbKeyToJSValue
static JSValue idbKeyToJSValue(ExecState* exec, JSGlobalObject* globalObject, IDBKey* key)
{
if (!key || !exec) {
// This should be undefined, not null.
// Spec: http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBKeyRange
return jsUndefined();
}
Locker<JSLock> locker(exec->vm().apiLock());
switch (key->type()) {
case KeyType::Array:
{
const Vector<RefPtr<IDBKey>>& inArray = key->array();
size_t size = inArray.size();
JSArray* outArray = constructEmptyArray(exec, 0, globalObject, size);
for (size_t i = 0; i < size; ++i) {
IDBKey* arrayKey = inArray.at(i).get();
outArray->putDirectIndex(exec, i, idbKeyToJSValue(exec, globalObject, arrayKey));
}
return JSValue(outArray);
}
case KeyType::String:
return jsStringWithCache(exec, key->string());
case KeyType::Date:
return jsDateOrNull(exec, key->date());
case KeyType::Number:
return jsNumber(key->number());
case KeyType::Min:
case KeyType::Max:
case KeyType::Invalid:
ASSERT_NOT_REACHED();
return jsUndefined();
}
ASSERT_NOT_REACHED();
return jsUndefined();
}
示例14: createIDBKeyFromValue
static RefPtr<IDBKey> createIDBKeyFromValue(ExecState* exec, JSValue value, Vector<JSArray*>& stack)
{
if (value.isNumber() && !std::isnan(value.toNumber(exec)))
return IDBKey::createNumber(value.toNumber(exec));
if (value.isString())
return IDBKey::createString(value.toString(exec)->value(exec));
if (value.inherits(DateInstance::info()) && !std::isnan(valueToDate(exec, value)))
return IDBKey::createDate(valueToDate(exec, value));
if (value.isObject()) {
JSObject* object = asObject(value);
if (isJSArray(object) || object->inherits(JSArray::info())) {
JSArray* array = asArray(object);
size_t length = array->length();
if (stack.contains(array))
return nullptr;
if (stack.size() >= maximumDepth)
return nullptr;
stack.append(array);
Vector<RefPtr<IDBKey>> subkeys;
for (size_t i = 0; i < length; i++) {
JSValue item = array->getIndex(exec, i);
RefPtr<IDBKey> subkey = createIDBKeyFromValue(exec, item, stack);
if (!subkey)
subkeys.append(IDBKey::createInvalid());
else
subkeys.append(subkey);
}
stack.removeLast();
return IDBKey::createArray(subkeys);
}
}
return nullptr;
}
示例15: cryptoKeyUsagesFromJSValue
static bool cryptoKeyUsagesFromJSValue(ExecState& state, JSValue value, CryptoKeyUsageBitmap& result)
{
VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (!isJSArray(value)) {
throwTypeError(&state, scope);
return false;
}
result = 0;
JSArray* array = asArray(value);
for (size_t i = 0; i < array->length(); ++i) {
JSValue element = array->getIndex(&state, i);
String usageString = element.toString(&state)->value(&state);
RETURN_IF_EXCEPTION(scope, false);
if (usageString == "encrypt")
result |= CryptoKeyUsageEncrypt;
else if (usageString == "decrypt")
result |= CryptoKeyUsageDecrypt;
else if (usageString == "sign")
result |= CryptoKeyUsageSign;
else if (usageString == "verify")
result |= CryptoKeyUsageVerify;
else if (usageString == "deriveKey")
result |= CryptoKeyUsageDeriveKey;
else if (usageString == "deriveBits")
result |= CryptoKeyUsageDeriveBits;
else if (usageString == "wrapKey")
result |= CryptoKeyUsageWrapKey;
else if (usageString == "unwrapKey")
result |= CryptoKeyUsageUnwrapKey;
}
return true;
}