PassRefPtr<SerializedScriptValue> InjectedScript::callFrames() { ASSERT(!hasNoValue()); ScriptFunctionCall function(m_injectedScriptObject, "callFrames"); ScriptValue callFramesValue = function.call(); return callFramesValue.serialize(m_injectedScriptObject.scriptState()); }
PassRefPtr<Intent> Intent::create(ScriptState* scriptState, const Dictionary& options, ExceptionCode& ec) { String action; if (!options.get("action", action) || action.isEmpty()) { ec = SYNTAX_ERR; return 0; } String type; if (!options.get("type", type) || type.isEmpty()) { ec = SYNTAX_ERR; return 0; } String service; KURL serviceUrl; if (options.get("service", service) && !service.isEmpty()) { serviceUrl = KURL(KURL(), service); if (!serviceUrl.isValid()) { ec = SYNTAX_ERR; return 0; } } MessagePortArray ports; OwnPtr<MessagePortChannelArray> channels; if (options.get("transfer", ports)) channels = MessagePort::disentanglePorts(&ports, ec); ScriptValue dataValue; RefPtr<SerializedScriptValue> serializedData; if (options.get("data", dataValue)) { bool didThrow = false; serializedData = dataValue.serialize(scriptState, &ports, 0, didThrow); if (didThrow) { ec = DATA_CLONE_ERR; return 0; } } HashMap<String, String> extras; Dictionary extrasDictionary; if (options.get("extras", extrasDictionary)) extrasDictionary.getOwnPropertiesAsStringHashMap(extras); HashSet<AtomicString> suggestionsStrings; Vector<KURL> suggestions; if (options.get("suggestions", suggestionsStrings)) { for (HashSet<AtomicString>::iterator iter = suggestionsStrings.begin(); iter != suggestionsStrings.end(); ++iter) { KURL suggestedURL = KURL(KURL(), *iter); if (!suggestedURL.isValid()) { ec = SYNTAX_ERR; return 0; } suggestions.append(suggestedURL); } } return adoptRef(new Intent(action, type, serializedData.release(), channels.release(), extras, serviceUrl, suggestions)); }
PassRefPtr<SerializedScriptValue> InjectedScript::wrapForConsole(ScriptValue value) { ASSERT(!hasNoValue()); ScriptFunctionCall wrapFunction(m_injectedScriptObject, "wrapObjectForConsole"); wrapFunction.appendArgument(value); wrapFunction.appendArgument(canAccessInspectedWindow()); bool hadException = false; ScriptValue r = wrapFunction.call(hadException); if (hadException) return SerializedScriptValue::create("<exception>"); return r.serialize(m_injectedScriptObject.scriptState()); }
void InjectedScript::dispatch(long callId, const String& methodName, const String& arguments, bool async, RefPtr<SerializedScriptValue>* result, bool* hadException) { ASSERT(!hasNoValue()); if (!canAccessInspectedWindow()) { *hadException = true; return; } ScriptFunctionCall function(m_injectedScriptObject, "dispatch"); function.appendArgument(methodName); function.appendArgument(arguments); if (async) function.appendArgument(callId); *hadException = false; ScriptValue resultValue = function.call(*hadException); if (!*hadException) *result = resultValue.serialize(m_injectedScriptObject.scriptState()); }
PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, PassRefPtr<IDBKey> prpKey, ExceptionCode& ec) { RefPtr<IDBKey> key = prpKey; if (isDeleted()) { ec = IDBDatabaseException::InvalidStateError; return 0; } if (!m_transaction->isActive()) { ec = IDBDatabaseException::TransactionInactiveError; return 0; } if (m_transaction->isReadOnly()) { ec = IDBDatabaseException::ReadOnlyError; return 0; } // FIXME: Expose the JS engine exception state through ScriptState. bool didThrow = false; RefPtr<SerializedScriptValue> serializedValue = value.serialize(state, 0, 0, didThrow); if (didThrow) { // Setting an explicit ExceptionCode here would defer handling the already thrown exception. return 0; } if (serializedValue->blobURLs().size() > 0) { // FIXME: Add Blob/File/FileList support ec = IDBDatabaseException::DataCloneError; return 0; } const IDBKeyPath& keyPath = m_metadata.keyPath; const bool usesInLineKeys = !keyPath.isNull(); const bool hasKeyGenerator = autoIncrement(); ScriptExecutionContext* context = scriptExecutionContextFromScriptState(state); DOMRequestState requestState(context); if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys && key) { ec = IDBDatabaseException::DataError; return 0; } if (!usesInLineKeys && !hasKeyGenerator && !key) { ec = IDBDatabaseException::DataError; return 0; } if (usesInLineKeys) { RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&requestState, value, keyPath); if (keyPathKey && !keyPathKey->isValid()) { ec = IDBDatabaseException::DataError; return 0; } if (!hasKeyGenerator && !keyPathKey) { ec = IDBDatabaseException::DataError; return 0; } if (hasKeyGenerator && !keyPathKey) { if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) { ec = IDBDatabaseException::DataError; return 0; } } if (keyPathKey) key = keyPathKey; } if (key && !key->isValid()) { ec = IDBDatabaseException::DataError; return 0; } Vector<int64_t> indexIds; Vector<IndexKeys> indexKeys; for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it) { IndexKeys keys; generateIndexKeysForValue(&requestState, it->value, value, &keys); indexIds.append(it->key); indexKeys.append(keys); } RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transaction.get()); Vector<uint8_t> valueBytes = serializedValue->toWireBytes(); // This is a hack to account for disagreements about whether SerializedScriptValue should deal in Vector<uint8_t> or Vector<char>. // See https://lists.webkit.org/pipermail/webkit-dev/2013-February/023682.html Vector<char>* valueBytesSigned = reinterpret_cast<Vector<char>*>(&valueBytes); RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(*valueBytesSigned); backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), static_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, indexKeys); return request.release(); }