bool injectIDBKeyIntoScriptValue(JSC::ExecState& exec, const IDBKeyData& keyData, JSC::JSValue value, const IDBKeyPath& keyPath) { LOG(IndexedDB, "injectIDBKeyIntoScriptValue"); ASSERT(keyPath.type() == IndexedDB::KeyPathType::String); Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath.string(), keyPathElements, error); ASSERT(error == IDBKeyPathParseError::None); if (keyPathElements.isEmpty()) return false; JSValue parent = ensureNthValueOnKeyPath(&exec, value, keyPathElements, keyPathElements.size() - 1); if (parent.isUndefined()) return false; auto key = keyData.maybeCreateIDBKey(); if (!key) return false; if (!set(&exec, parent, keyPathElements.last(), idbKeyToJSValue(&exec, exec.lexicalGlobalObject(), key.get()))) return false; return true; }
static JSValue idbValueDataToJSValue(JSC::ExecState& exec, const Vector<uint8_t>& buffer) { if (buffer.isEmpty()) return jsNull(); RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::createFromWireBytes(buffer); return serializedValue->deserialize(&exec, exec.lexicalGlobalObject(), 0, NonThrowing); }
void willCreatePossiblyOrphanedTreeByRemovalSlowCase(Node* root) { JSC::ExecState* scriptState = mainWorldExecState(root->document().frame()); if (!scriptState) return; JSLockHolder lock(scriptState); toJS(scriptState, static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()), root); }
void InjectedBundle::reportException(JSContextRef context, JSValueRef exception) { if (!context || !exception) return; JSLock lock(JSC::SilenceAssertionsOnly); JSC::ExecState* execState = toJS(context); // Make sure the context has a DOMWindow global object, otherwise this context didn't originate from a Page. if (!toJSDOMWindow(execState->lexicalGlobalObject())) return; WebCore::reportException(execState, toJS(execState, exception)); }
JSC::JSValue deserializeIDBValueDataToJSValue(JSC::ExecState& exec, const ThreadSafeDataBuffer& valueData) { if (!valueData.data()) return jsUndefined(); const Vector<uint8_t>& data = *valueData.data(); JSValue result; if (data.size()) { RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::createFromWireBytes(data); exec.vm().apiLock().lock(); result = serializedValue->deserialize(&exec, exec.lexicalGlobalObject(), 0, NonThrowing); exec.vm().apiLock().unlock(); } else result = jsNull(); return result; }
Ref<ReadableStream> ReadableStream::create(JSC::ExecState& execState, RefPtr<ReadableStreamSource>&& source) { VM& vm = execState.vm(); auto scope = DECLARE_CATCH_SCOPE(vm); auto& clientData = *static_cast<JSVMClientData*>(vm.clientData); auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(execState.lexicalGlobalObject()); auto* constructor = JSC::asObject(globalObject.get(&execState, clientData.builtinNames().ReadableStreamPrivateName())); ConstructData constructData; ConstructType constructType = constructor->methodTable(vm)->getConstructData(constructor, constructData); ASSERT(constructType != ConstructType::None); MarkedArgumentBuffer args; args.append(source ? toJSNewlyCreated(&execState, &globalObject, source.releaseNonNull()) : JSC::jsUndefined()); ASSERT(!args.hasOverflowed()); auto newReadableStream = jsDynamicCast<JSReadableStream*>(vm, JSC::construct(&execState, constructor, constructType, constructData, args)); scope.assertNoException(); return create(globalObject, *newReadableStream); }
JSValue idbKeyDataToJSValue(JSC::ExecState& exec, const IDBKeyData& keyData) { if (keyData.isNull()) return jsUndefined(); Locker<JSLock> locker(exec.vm().apiLock()); switch (keyData.type()) { case KeyType::Array: { const Vector<IDBKeyData>& inArray = keyData.array(); size_t size = inArray.size(); JSArray* outArray = constructEmptyArray(&exec, 0, exec.lexicalGlobalObject(), size); for (size_t i = 0; i < size; ++i) { auto& arrayKey = inArray.at(i); outArray->putDirectIndex(&exec, i, idbKeyDataToJSValue(exec, arrayKey)); } return JSValue(outArray); } case KeyType::String: return jsStringWithCache(&exec, keyData.string()); case KeyType::Date: return jsDateOrNull(&exec, keyData.date()); case KeyType::Number: return jsNumber(keyData.number()); case KeyType::Min: case KeyType::Max: case KeyType::Invalid: ASSERT_NOT_REACHED(); return jsUndefined(); } ASSERT_NOT_REACHED(); return jsUndefined(); }
void reportDeprecatedSetterError(JSC::ExecState& state, const char* interfaceName, const char* attributeName) { auto& context = *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->scriptExecutionContext(); context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Deprecated attempt to set property '", attributeName, "' on a non-", interfaceName, " object.")); }
JSC::EncodedJSValue reportDeprecatedGetterError(JSC::ExecState& state, const char* interfaceName, const char* attributeName) { auto& context = *jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->scriptExecutionContext(); context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Deprecated attempt to access property '", attributeName, "' on a non-", interfaceName, " object.")); return JSValue::encode(jsUndefined()); }
static FontFaceSet::Promise createPromise(JSC::ExecState& exec) { JSDOMGlobalObject& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(exec.lexicalGlobalObject()); return FontFaceSet::Promise(DeferredWrapper(&exec, &globalObject, JSC::JSPromiseDeferred::create(&exec, &globalObject))); }