JSValue QtInstance::invokeMethod(ExecState*, RuntimeMethod*) { // Implemented via fallbackMethod & QtRuntimeMetaMethod::callAsFunction return jsUndefined(); }
EncodedJSValue JSC_HOST_CALL JSBlobConstructor::constructJSBlob(ExecState* exec) { JSBlobConstructor* jsConstructor = jsCast<JSBlobConstructor*>(exec->callee()); ScriptExecutionContext* context = jsConstructor->scriptExecutionContext(); if (!context) return throwVMError(exec, createReferenceError(exec, "Blob constructor associated document is unavailable")); if (!exec->argumentCount()) { RefPtr<Blob> blob = Blob::create(); return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), Blob, blob.get())); } JSValue firstArg = exec->argument(0); if (!isJSArray(firstArg)) return throwVMError(exec, createTypeError(exec, "First argument of the constructor is not of type Array")); String type; String endings = "transparent"; if (exec->argumentCount() > 1) { JSValue blobPropertyBagValue = exec->argument(1); if (!blobPropertyBagValue.isObject()) return throwVMError(exec, createTypeError(exec, "Second argument of the constructor is not of type Object")); // Given the above test, this will always yield an object. JSObject* blobPropertyBagObject = blobPropertyBagValue.toObject(exec); // Create the dictionary wrapper from the initializer object. JSDictionary dictionary(exec, blobPropertyBagObject); // Attempt to get the endings property and validate it. bool containsEndings = dictionary.get("endings", endings); if (exec->hadException()) return JSValue::encode(jsUndefined()); if (containsEndings) { if (endings != "transparent" && endings != "native") return throwVMError(exec, createTypeError(exec, "The endings property must be either \"transparent\" or \"native\"")); } // Attempt to get the type property. dictionary.get("type", type); if (exec->hadException()) return JSValue::encode(jsUndefined()); if (!type.containsOnlyASCII()) return throwVMError(exec, createSyntaxError(exec, "type must consist of ASCII characters")); } ASSERT(endings == "transparent" || endings == "native"); // FIXME: this would be better if the WebKitBlobBuilder were a stack object to avoid the allocation. RefPtr<WebKitBlobBuilder> blobBuilder = WebKitBlobBuilder::create(); JSArray* array = asArray(firstArg); unsigned length = array->length(); for (unsigned i = 0; i < length; ++i) { JSValue item = array->getIndex(i); #if ENABLE(BLOB) if (item.inherits(&JSArrayBuffer::s_info)) blobBuilder->append(context, toArrayBuffer(item)); else if (item.inherits(&JSArrayBufferView::s_info)) blobBuilder->append(toArrayBufferView(item)); else #endif if (item.inherits(&JSBlob::s_info)) blobBuilder->append(toBlob(item)); else { String string = ustringToString(item.toString(exec)->value(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); blobBuilder->append(string, endings, ASSERT_NO_EXCEPTION); } } RefPtr<Blob> blob = blobBuilder->getBlob(type); return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), Blob, blob.get())); }
void JSGlobalObject::reset(JSValue prototype) { ExecState* exec = JSGlobalObject::globalExec(); m_functionPrototype.set(exec->vm(), this, FunctionPrototype::create(exec, this, FunctionPrototype::createStructure(exec->vm(), this, jsNull()))); // The real prototype will be set once ObjectPrototype is created. m_functionStructure.set(exec->vm(), this, JSFunction::createStructure(exec->vm(), this, m_functionPrototype.get())); m_boundFunctionStructure.set(exec->vm(), this, JSBoundFunction::createStructure(exec->vm(), this, m_functionPrototype.get())); m_namedFunctionStructure.set(exec->vm(), this, Structure::addPropertyTransition(exec->vm(), m_functionStructure.get(), exec->vm().propertyNames->name, DontDelete | ReadOnly | DontEnum, 0, m_functionNameOffset)); m_internalFunctionStructure.set(exec->vm(), this, InternalFunction::createStructure(exec->vm(), this, m_functionPrototype.get())); JSFunction* callFunction = 0; JSFunction* applyFunction = 0; m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction); m_callFunction.set(exec->vm(), this, callFunction); m_applyFunction.set(exec->vm(), this, applyFunction); m_objectPrototype.set(exec->vm(), this, ObjectPrototype::create(exec, this, ObjectPrototype::createStructure(exec->vm(), this, jsNull()))); GetterSetter* protoAccessor = GetterSetter::create(exec); protoAccessor->setGetter(exec->vm(), JSFunction::create(exec, this, 0, String(), globalFuncProtoGetter)); protoAccessor->setSetter(exec->vm(), JSFunction::create(exec, this, 0, String(), globalFuncProtoSetter)); m_objectPrototype->putDirectAccessor(exec, exec->propertyNames().underscoreProto, protoAccessor, Accessor | DontEnum); m_functionPrototype->structure()->setPrototypeWithoutTransition(exec->vm(), m_objectPrototype.get()); m_nameScopeStructure.set(exec->vm(), this, JSNameScope::createStructure(exec->vm(), this, jsNull())); m_activationStructure.set(exec->vm(), this, JSActivation::createStructure(exec->vm(), this, jsNull())); m_strictEvalActivationStructure.set(exec->vm(), this, StrictEvalActivation::createStructure(exec->vm(), this, jsNull())); m_withScopeStructure.set(exec->vm(), this, JSWithScope::createStructure(exec->vm(), this, jsNull())); m_nullPrototypeObjectStructure.set(exec->vm(), this, JSFinalObject::createStructure(vm(), this, jsNull(), JSFinalObject::defaultInlineCapacity())); m_callbackFunctionStructure.set(exec->vm(), this, JSCallbackFunction::createStructure(exec->vm(), this, m_functionPrototype.get())); m_argumentsStructure.set(exec->vm(), this, Arguments::createStructure(exec->vm(), this, m_objectPrototype.get())); m_callbackConstructorStructure.set(exec->vm(), this, JSCallbackConstructor::createStructure(exec->vm(), this, m_objectPrototype.get())); m_callbackObjectStructure.set(exec->vm(), this, JSCallbackObject<JSDestructibleObject>::createStructure(exec->vm(), this, m_objectPrototype.get())); #if JSC_OBJC_API_ENABLED m_objcCallbackFunctionStructure.set(exec->vm(), this, ObjCCallbackFunction::createStructure(exec->vm(), this, m_functionPrototype.get())); m_objcWrapperObjectStructure.set(exec->vm(), this, JSCallbackObject<JSAPIWrapperObject>::createStructure(exec->vm(), this, m_objectPrototype.get())); #endif m_arrayPrototype.set(exec->vm(), this, ArrayPrototype::create(exec, this, ArrayPrototype::createStructure(exec->vm(), this, m_objectPrototype.get()))); m_originalArrayStructureForIndexingShape[UndecidedShape >> IndexingShapeShift].set(exec->vm(), this, JSArray::createStructure(exec->vm(), this, m_arrayPrototype.get(), ArrayWithUndecided)); m_originalArrayStructureForIndexingShape[Int32Shape >> IndexingShapeShift].set(exec->vm(), this, JSArray::createStructure(exec->vm(), this, m_arrayPrototype.get(), ArrayWithInt32)); m_originalArrayStructureForIndexingShape[DoubleShape >> IndexingShapeShift].set(exec->vm(), this, JSArray::createStructure(exec->vm(), this, m_arrayPrototype.get(), ArrayWithDouble)); m_originalArrayStructureForIndexingShape[ContiguousShape >> IndexingShapeShift].set(exec->vm(), this, JSArray::createStructure(exec->vm(), this, m_arrayPrototype.get(), ArrayWithContiguous)); m_originalArrayStructureForIndexingShape[ArrayStorageShape >> IndexingShapeShift].set(exec->vm(), this, JSArray::createStructure(exec->vm(), this, m_arrayPrototype.get(), ArrayWithArrayStorage)); m_originalArrayStructureForIndexingShape[SlowPutArrayStorageShape >> IndexingShapeShift].set(exec->vm(), this, JSArray::createStructure(exec->vm(), this, m_arrayPrototype.get(), ArrayWithSlowPutArrayStorage)); for (unsigned i = 0; i < NumberOfIndexingShapes; ++i) m_arrayStructureForIndexingShapeDuringAllocation[i] = m_originalArrayStructureForIndexingShape[i]; m_regExpMatchesArrayStructure.set(exec->vm(), this, RegExpMatchesArray::createStructure(exec->vm(), this, m_arrayPrototype.get())); m_stringPrototype.set(exec->vm(), this, StringPrototype::create(exec, this, StringPrototype::createStructure(exec->vm(), this, m_objectPrototype.get()))); m_stringObjectStructure.set(exec->vm(), this, StringObject::createStructure(exec->vm(), this, m_stringPrototype.get())); m_booleanPrototype.set(exec->vm(), this, BooleanPrototype::create(exec, this, BooleanPrototype::createStructure(exec->vm(), this, m_objectPrototype.get()))); m_booleanObjectStructure.set(exec->vm(), this, BooleanObject::createStructure(exec->vm(), this, m_booleanPrototype.get())); m_numberPrototype.set(exec->vm(), this, NumberPrototype::create(exec, this, NumberPrototype::createStructure(exec->vm(), this, m_objectPrototype.get()))); m_numberObjectStructure.set(exec->vm(), this, NumberObject::createStructure(exec->vm(), this, m_numberPrototype.get())); m_datePrototype.set(exec->vm(), this, DatePrototype::create(exec, this, DatePrototype::createStructure(exec->vm(), this, m_objectPrototype.get()))); m_dateStructure.set(exec->vm(), this, DateInstance::createStructure(exec->vm(), this, m_datePrototype.get())); RegExp* emptyRegex = RegExp::create(exec->vm(), "", NoFlags); m_regExpPrototype.set(exec->vm(), this, RegExpPrototype::create(exec, this, RegExpPrototype::createStructure(exec->vm(), this, m_objectPrototype.get()), emptyRegex)); m_regExpStructure.set(exec->vm(), this, RegExpObject::createStructure(exec->vm(), this, m_regExpPrototype.get())); m_errorPrototype.set(exec->vm(), this, ErrorPrototype::create(exec, this, ErrorPrototype::createStructure(exec->vm(), this, m_objectPrototype.get()))); m_errorStructure.set(exec->vm(), this, ErrorInstance::createStructure(exec->vm(), this, m_errorPrototype.get())); // Constructors JSCell* objectConstructor = ObjectConstructor::create(exec, this, ObjectConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_objectPrototype.get()); JSCell* functionConstructor = FunctionConstructor::create(exec, this, FunctionConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_functionPrototype.get()); JSCell* arrayConstructor = ArrayConstructor::create(exec, this, ArrayConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_arrayPrototype.get()); JSCell* stringConstructor = StringConstructor::create(exec, this, StringConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_stringPrototype.get()); JSCell* booleanConstructor = BooleanConstructor::create(exec, this, BooleanConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_booleanPrototype.get()); JSCell* numberConstructor = NumberConstructor::create(exec, this, NumberConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_numberPrototype.get()); JSCell* dateConstructor = DateConstructor::create(exec, this, DateConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_datePrototype.get()); m_regExpConstructor.set(exec->vm(), this, RegExpConstructor::create(exec, this, RegExpConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_regExpPrototype.get())); m_errorConstructor.set(exec->vm(), this, ErrorConstructor::create(exec, this, ErrorConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), m_errorPrototype.get())); Structure* nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(exec->vm(), this, m_errorPrototype.get()); Structure* nativeErrorStructure = NativeErrorConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()); m_evalErrorConstructor.set(exec->vm(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("EvalError"))); m_rangeErrorConstructor.set(exec->vm(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("RangeError"))); m_referenceErrorConstructor.set(exec->vm(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("ReferenceError"))); m_syntaxErrorConstructor.set(exec->vm(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("SyntaxError"))); m_typeErrorConstructor.set(exec->vm(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("TypeError"))); m_URIErrorConstructor.set(exec->vm(), this, NativeErrorConstructor::create(exec, this, nativeErrorStructure, nativeErrorPrototypeStructure, ASCIILiteral("URIError"))); m_objectPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, objectConstructor, DontEnum); m_functionPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, functionConstructor, DontEnum); m_arrayPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, arrayConstructor, DontEnum); m_booleanPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, booleanConstructor, DontEnum); m_stringPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, stringConstructor, DontEnum); m_numberPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, numberConstructor, DontEnum); m_datePrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, dateConstructor, DontEnum); m_regExpPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, m_regExpConstructor.get(), DontEnum); m_errorPrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, m_errorConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), exec->propertyNames().Object, objectConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "Function"), functionConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), exec->propertyNames().Array, arrayConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "Boolean"), booleanConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "String"), stringConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "Number"), numberConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "Date"), dateConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "RegExp"), m_regExpConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "Error"), m_errorConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "EvalError"), m_evalErrorConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "RangeError"), m_rangeErrorConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "ReferenceError"), m_referenceErrorConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "SyntaxError"), m_syntaxErrorConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "TypeError"), m_typeErrorConstructor.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "URIError"), m_URIErrorConstructor.get(), DontEnum); m_evalFunction.set(exec->vm(), this, JSFunction::create(exec, this, 1, exec->propertyNames().eval.string(), globalFuncEval)); putDirectWithoutTransition(exec->vm(), exec->propertyNames().eval, m_evalFunction.get(), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "JSON"), JSONObject::create(exec, this, JSONObject::createStructure(exec->vm(), this, m_objectPrototype.get())), DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "Math"), MathObject::create(exec, this, MathObject::createStructure(exec->vm(), this, m_objectPrototype.get())), DontEnum); GlobalPropertyInfo staticGlobals[] = { GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(), DontEnum | DontDelete | ReadOnly), GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly), GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete | ReadOnly) }; addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals)); m_specialPointers[Special::CallFunction] = m_callFunction.get(); m_specialPointers[Special::ApplyFunction] = m_applyFunction.get(); m_specialPointers[Special::ObjectConstructor] = objectConstructor; m_specialPointers[Special::ArrayConstructor] = arrayConstructor; if (m_experimentsEnabled) { NamePrototype* privateNamePrototype = NamePrototype::create(exec, NamePrototype::createStructure(exec->vm(), this, m_objectPrototype.get())); m_privateNameStructure.set(exec->vm(), this, NameInstance::createStructure(exec->vm(), this, privateNamePrototype)); JSCell* privateNameConstructor = NameConstructor::create(exec, this, NameConstructor::createStructure(exec->vm(), this, m_functionPrototype.get()), privateNamePrototype); privateNamePrototype->putDirectWithoutTransition(exec->vm(), exec->propertyNames().constructor, privateNameConstructor, DontEnum); putDirectWithoutTransition(exec->vm(), Identifier(exec, "Name"), privateNameConstructor, DontEnum); } resetPrototype(exec->vm(), prototype); }
JSValue jsHTMLIFrameElementContentDocument(ExecState* exec, JSValue slotBase, const Identifier&) { JSHTMLIFrameElement* castedThis = static_cast<JSHTMLIFrameElement*>(asObject(slotBase)); HTMLIFrameElement* imp = static_cast<HTMLIFrameElement*>(castedThis->impl()); return checkNodeSecurity(exec, imp->contentDocument()) ? toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->contentDocument())) : jsUndefined(); }
static CompilationResult compileImpl( ExecState* exec, CodeBlock* codeBlock, CompilationMode mode, unsigned osrEntryBytecodeIndex, PassRefPtr<DeferredCompilationCallback> callback, Worklist* worklist) { SamplingRegion samplingRegion("DFG Compilation (Driver)"); numCompilations++; ASSERT(codeBlock); ASSERT(codeBlock->alternative()); ASSERT(codeBlock->alternative()->jitType() == JITCode::BaselineJIT); ASSERT(osrEntryBytecodeIndex != UINT_MAX); if (!Options::useDFGJIT() || !MacroAssembler::supportsFloatingPoint()) return CompilationFailed; if (!Options::bytecodeRangeToDFGCompile().isInRange(codeBlock->instructionCount())) return CompilationFailed; if (logCompilationChanges()) dataLog("DFG(Driver) compiling ", *codeBlock, ", number of instructions = ", codeBlock->instructionCount(), "\n"); VM& vm = exec->vm(); // Make sure that any stubs that the DFG is going to use are initialized. We want to // make sure that al JIT code generation does finalization on the main thread. vm.getCTIStub(osrExitGenerationThunkGenerator); vm.getCTIStub(throwExceptionFromCallSlowPathGenerator); vm.getCTIStub(linkCallThunkGenerator); vm.getCTIStub(linkConstructThunkGenerator); vm.getCTIStub(linkClosureCallThunkGenerator); vm.getCTIStub(virtualCallThunkGenerator); vm.getCTIStub(virtualConstructThunkGenerator); #if ENABLE(FTL_JIT) vm.getCTIStub(FTL::osrExitGenerationThunkGenerator); #endif // Derive our set of must-handle values. The compilation must be at least conservative // enough to allow for OSR entry with these values. unsigned numVarsWithValues; if (osrEntryBytecodeIndex) numVarsWithValues = codeBlock->m_numVars; else numVarsWithValues = 0; RefPtr<Plan> plan = adoptRef( new Plan(codeBlock, mode, osrEntryBytecodeIndex, numVarsWithValues)); for (size_t i = 0; i < plan->mustHandleValues.size(); ++i) { int operand = plan->mustHandleValues.operandForIndex(i); if (operandIsArgument(operand) && !operandToArgument(operand) && codeBlock->codeType() == FunctionCode && codeBlock->specializationKind() == CodeForConstruct) { // Ugh. If we're in a constructor, the 'this' argument may hold garbage. It will // also never be used. It doesn't matter what we put into the value for this, // but it has to be an actual value that can be grokked by subsequent DFG passes, // so we sanitize it here by turning it into Undefined. plan->mustHandleValues[i] = jsUndefined(); } else plan->mustHandleValues[i] = exec->uncheckedR(operand).jsValue(); } if (worklist) { plan->callback = callback; if (logCompilationChanges()) dataLog("Deferring DFG compilation of ", *codeBlock, " with queue length ", worklist->queueLength(), ".\n"); worklist->enqueue(plan); return CompilationDeferred; } plan->compileInThread(*vm.dfgState); return plan->finalizeWithoutNotifyingCallback(); }
JSValue* JSDocumentPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { if (!thisObj->inherits(&JSDocument::info)) return throwError(exec, TypeError); JSDocument* castedThisObj = static_cast<JSDocument*>(thisObj); Document* imp = static_cast<Document*>(castedThisObj->impl()); switch (id) { case JSDocument::CreateElementFuncNum: { ExceptionCode ec = 0; String tagName = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createElement(tagName, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateDocumentFragmentFuncNum: { KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createDocumentFragment())); return result; } case JSDocument::CreateTextNodeFuncNum: { String data = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createTextNode(data))); return result; } case JSDocument::CreateCommentFuncNum: { String data = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createComment(data))); return result; } case JSDocument::CreateCDATASectionFuncNum: { ExceptionCode ec = 0; String data = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createCDATASection(data, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateProcessingInstructionFuncNum: { ExceptionCode ec = 0; String target = args[0]->toString(exec); String data = args[1]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createProcessingInstruction(target, data, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateAttributeFuncNum: { ExceptionCode ec = 0; String name = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createAttribute(name, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateEntityReferenceFuncNum: { ExceptionCode ec = 0; String name = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createEntityReference(name, ec))); setDOMException(exec, ec); return result; } case JSDocument::GetElementsByTagNameFuncNum: { String tagname = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getElementsByTagName(tagname))); return result; } case JSDocument::ImportNodeFuncNum: { ExceptionCode ec = 0; Node* importedNode = toNode(args[0]); bool deep = args[1]->toBoolean(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->importNode(importedNode, deep, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateElementNSFuncNum: { ExceptionCode ec = 0; String namespaceURI = valueToStringWithNullCheck(exec, args[0]); String qualifiedName = args[1]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createElementNS(namespaceURI, qualifiedName, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateAttributeNSFuncNum: { ExceptionCode ec = 0; String namespaceURI = valueToStringWithNullCheck(exec, args[0]); String qualifiedName = args[1]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createAttributeNS(namespaceURI, qualifiedName, ec))); setDOMException(exec, ec); return result; } case JSDocument::GetElementsByTagNameNSFuncNum: { String namespaceURI = valueToStringWithNullCheck(exec, args[0]); String localName = args[1]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getElementsByTagNameNS(namespaceURI, localName))); return result; } case JSDocument::GetElementByIdFuncNum: { String elementId = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getElementById(elementId))); return result; } case JSDocument::AdoptNodeFuncNum: { ExceptionCode ec = 0; Node* source = toNode(args[0]); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->adoptNode(source, ec))); setDOMException(exec, ec); return result; } case JSDocument::LoadFuncNum: { String url = args[0]->toString(exec); KJS::JSValue* result = jsBoolean(imp->load(url)); return result; } case JSDocument::CreateEventFuncNum: { ExceptionCode ec = 0; String eventType = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createEvent(eventType, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateRangeFuncNum: { KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createRange())); return result; } case JSDocument::CreateNodeIteratorFuncNum: { ExceptionCode ec = 0; Node* root = toNode(args[0]); bool whatToShowOk; unsigned whatToShow = args[1]->toInt32(exec, whatToShowOk); if (!whatToShowOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } NodeFilter* filter = toNodeFilter(args[2]); bool entityReferenceExpansion = args[3]->toBoolean(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createNodeIterator(root, whatToShow, filter, entityReferenceExpansion, ec))); setDOMException(exec, ec); return result; } case JSDocument::CreateTreeWalkerFuncNum: { ExceptionCode ec = 0; Node* root = toNode(args[0]); bool whatToShowOk; unsigned whatToShow = args[1]->toInt32(exec, whatToShowOk); if (!whatToShowOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } NodeFilter* filter = toNodeFilter(args[2]); bool entityReferenceExpansion = args[3]->toBoolean(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createTreeWalker(root, whatToShow, filter, entityReferenceExpansion, ec))); setDOMException(exec, ec); return result; } case JSDocument::GetOverrideStyleFuncNum: { Element* element = toElement(args[0]); String pseudoElement = args[1]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getOverrideStyle(element, pseudoElement))); return result; } case JSDocument::ExecCommandFuncNum: { String command = args[0]->toString(exec); bool userInterface = args[1]->toBoolean(exec); String value = valueToStringWithUndefinedOrNullCheck(exec, args[2]); KJS::JSValue* result = jsBoolean(imp->execCommand(command, userInterface, value)); return result; } case JSDocument::QueryCommandEnabledFuncNum: { String command = args[0]->toString(exec); KJS::JSValue* result = jsBoolean(imp->queryCommandEnabled(command)); return result; } case JSDocument::QueryCommandIndetermFuncNum: { String command = args[0]->toString(exec); KJS::JSValue* result = jsBoolean(imp->queryCommandIndeterm(command)); return result; } case JSDocument::QueryCommandStateFuncNum: { String command = args[0]->toString(exec); KJS::JSValue* result = jsBoolean(imp->queryCommandState(command)); return result; } case JSDocument::QueryCommandSupportedFuncNum: { String command = args[0]->toString(exec); KJS::JSValue* result = jsBoolean(imp->queryCommandSupported(command)); return result; } case JSDocument::QueryCommandValueFuncNum: { String command = args[0]->toString(exec); KJS::JSValue* result = jsStringOrFalse(imp->queryCommandValue(command)); return result; } case JSDocument::GetElementsByNameFuncNum: { String elementName = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getElementsByName(elementName))); return result; } case JSDocument::ElementFromPointFuncNum: { bool xOk; int x = args[0]->toInt32(exec, xOk); if (!xOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } bool yOk; int y = args[1]->toInt32(exec, yOk); if (!yOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->elementFromPoint(x, y))); return result; } } return 0; }
static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) { if (exec->argumentCount() != 2) return throwSyntaxError(exec); WebGLUniformLocation* location = 0; long index = -1; if (functionForUniform(f)) { if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info)) return throwTypeError(exec); location = toWebGLUniformLocation(exec->argument(0)); } else index = exec->argument(0).toInt32(exec); if (exec->hadException()) return jsUndefined(); RefPtr<Float32Array> webGLArray = toFloat32Array(exec->argument(1)); if (exec->hadException()) return jsUndefined(); ExceptionCode ec = 0; if (webGLArray) { switch (f) { case f_uniform1v: context->uniform1fv(location, webGLArray.get(), ec); break; case f_uniform2v: context->uniform2fv(location, webGLArray.get(), ec); break; case f_uniform3v: context->uniform3fv(location, webGLArray.get(), ec); break; case f_uniform4v: context->uniform4fv(location, webGLArray.get(), ec); break; case f_vertexAttrib1v: context->vertexAttrib1fv(index, webGLArray.get()); break; case f_vertexAttrib2v: context->vertexAttrib2fv(index, webGLArray.get()); break; case f_vertexAttrib3v: context->vertexAttrib3fv(index, webGLArray.get()); break; case f_vertexAttrib4v: context->vertexAttrib4fv(index, webGLArray.get()); break; } setDOMException(exec, ec); return jsUndefined(); } Vector<float, 64> array; if (!toVector(exec, exec->argument(1), array)) return throwTypeError(exec); switch (f) { case f_uniform1v: context->uniform1fv(location, array.data(), array.size(), ec); break; case f_uniform2v: context->uniform2fv(location, array.data(), array.size(), ec); break; case f_uniform3v: context->uniform3fv(location, array.data(), array.size(), ec); break; case f_uniform4v: context->uniform4fv(location, array.data(), array.size(), ec); break; case f_vertexAttrib1v: context->vertexAttrib1fv(index, array.data(), array.size()); break; case f_vertexAttrib2v: context->vertexAttrib2fv(index, array.data(), array.size()); break; case f_vertexAttrib3v: context->vertexAttrib3fv(index, array.data(), array.size()); break; case f_vertexAttrib4v: context->vertexAttrib4fv(index, array.data(), array.size()); break; } setDOMException(exec, ec); return jsUndefined(); }
JSValue JSWebKitSubtleCrypto::importKey(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (state.argumentCount() < 3) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); CryptoKeyFormat keyFormat; auto success = cryptoKeyFormatFromJSValue(state, state.argument(0), keyFormat); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); CryptoOperationData data; success = cryptoOperationDataFromJSValue(&state, state.uncheckedArgument(1), data); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); RefPtr<CryptoAlgorithm> algorithm; RefPtr<CryptoAlgorithmParametersDeprecated> parameters; if (!state.uncheckedArgument(2).isNull()) { algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(2)); ASSERT(scope.exception() || algorithm); if (!algorithm) return jsUndefined(); parameters = JSCryptoAlgorithmDictionary::createParametersForImportKey(&state, algorithm->identifier(), state.uncheckedArgument(2)); ASSERT(scope.exception() || parameters); if (!parameters) return jsUndefined(); } bool extractable = false; if (state.argumentCount() >= 4) { extractable = state.uncheckedArgument(3).toBoolean(&state); RETURN_IF_EXCEPTION(scope, JSValue()); } CryptoKeyUsageBitmap keyUsages = 0; if (state.argumentCount() >= 5) { auto success = cryptoKeyUsagesFromJSValue(state, state.argument(4), keyUsages); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); } RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow()); auto promise = wrapper->promise(); auto successCallback = [wrapper](CryptoKey& result) mutable { wrapper->resolve(result); }; auto failureCallback = [wrapper]() mutable { wrapper->reject(nullptr); }; WebCore::importKey(state, keyFormat, data, WTFMove(algorithm), WTFMove(parameters), extractable, keyUsages, WTFMove(successCallback), WTFMove(failureCallback)); RETURN_IF_EXCEPTION(scope, JSValue()); return promise; }
JSValue JSWebKitSubtleCrypto::wrapKey(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (state.argumentCount() < 4) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); CryptoKeyFormat keyFormat; auto success = cryptoKeyFormatFromJSValue(state, state.argument(0), keyFormat); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1)); if (!key) return throwTypeError(&state, scope); RefPtr<CryptoKey> wrappingKey = JSCryptoKey::toWrapped(state.uncheckedArgument(2)); if (!key) return throwTypeError(&state, scope); if (!wrappingKey->allows(CryptoKeyUsageWrapKey)) { wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'wrapKey'")); setDOMException(&state, NOT_SUPPORTED_ERR); return jsUndefined(); } auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(3)); ASSERT(scope.exception() || algorithm); if (!algorithm) return jsUndefined(); auto parameters = JSCryptoAlgorithmDictionary::createParametersForEncrypt(&state, algorithm->identifier(), state.uncheckedArgument(3)); ASSERT(scope.exception() || parameters); if (!parameters) return jsUndefined(); RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow()); auto promise = wrapper->promise(); auto exportSuccessCallback = [keyFormat, algorithm, parameters, wrappingKey, wrapper](const Vector<uint8_t>& exportedKeyData) mutable { auto encryptSuccessCallback = [wrapper](const Vector<uint8_t>& encryptedData) mutable { fulfillPromiseWithArrayBuffer(wrapper.releaseNonNull(), encryptedData.data(), encryptedData.size()); }; auto encryptFailureCallback = [wrapper]() mutable { wrapper->reject(nullptr); }; auto result = algorithm->encryptForWrapKey(*parameters, *wrappingKey, std::make_pair(exportedKeyData.data(), exportedKeyData.size()), WTFMove(encryptSuccessCallback), WTFMove(encryptFailureCallback)); if (result.hasException()) { // FIXME: Report failure details to console, and possibly to calling script once there is a standardized way to pass errors to WebCrypto promise reject functions. wrapper->reject(nullptr); } }; auto exportFailureCallback = [wrapper]() mutable { wrapper->reject(nullptr); }; WebCore::exportKey(state, keyFormat, *key, WTFMove(exportSuccessCallback), WTFMove(exportFailureCallback)); return promise; }
JSValue JSLocation::reload(ExecState* exec) { impl()->reload(activeDOMWindow(exec)); return jsUndefined(); }
JSValue JSSQLTransaction::executeSql(ExecState* exec) { if (!exec->argumentCount()) { setDOMException(exec, SYNTAX_ERR); return jsUndefined(); } String sqlStatement = exec->argument(0).toString(exec)->value(exec); if (exec->hadException()) return jsUndefined(); // Now assemble the list of SQL arguments Vector<SQLValue> sqlValues; if (!exec->argument(1).isUndefinedOrNull()) { JSObject* object = exec->argument(1).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } JSValue lengthValue = object->get(exec, exec->propertyNames().length); if (exec->hadException()) return jsUndefined(); unsigned length = lengthValue.toUInt32(exec); if (exec->hadException()) return jsUndefined(); for (unsigned i = 0 ; i < length; ++i) { JSValue value = object->get(exec, i); if (exec->hadException()) return jsUndefined(); if (value.isUndefinedOrNull()) sqlValues.append(SQLValue()); else if (value.isNumber()) sqlValues.append(value.asNumber()); else { // Convert the argument to a string and append it sqlValues.append(value.toString(exec)->value(exec)); if (exec->hadException()) return jsUndefined(); } } } RefPtr<SQLStatementCallback> callback; if (!exec->argument(2).isUndefinedOrNull()) { JSObject* object = exec->argument(2).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } callback = JSSQLStatementCallback::create(object, jsCast<JSDOMGlobalObject*>(globalObject())); } RefPtr<SQLStatementErrorCallback> errorCallback; if (!exec->argument(3).isUndefinedOrNull()) { JSObject* object = exec->argument(3).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } errorCallback = JSSQLStatementErrorCallback::create(object, jsCast<JSDOMGlobalObject*>(globalObject())); } ExceptionCode ec = 0; m_impl->executeSQL(sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec); setDOMException(exec, ec); return jsUndefined(); }
JSValue JSWebGL2RenderingContext::getSyncParameter(ExecState& exec) { UNUSED_PARAM(exec); return jsUndefined(); }
JSValue JSWebGL2RenderingContext::getActiveUniformBlockName(ExecState& exec) { UNUSED_PARAM(exec); return jsUndefined(); }
static EncodedJSValue JSC_HOST_CALL callFunctionPrototype(ExecState*) { return JSValue::encode(jsUndefined()); }
JSValue* JSSVGTextContentElementPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { if (!thisObj->inherits(&JSSVGTextContentElement::info)) return throwError(exec, TypeError); SVGTextContentElement* imp = static_cast<SVGTextContentElement*>(static_cast<JSSVGTextContentElement*>(thisObj)->impl()); switch (id) { case JSSVGTextContentElement::GetNumberOfCharsFuncNum: { KJS::JSValue* result = jsNumber(imp->getNumberOfChars()); return result; } case JSSVGTextContentElement::GetComputedTextLengthFuncNum: { KJS::JSValue* result = jsNumber(imp->getComputedTextLength()); return result; } case JSSVGTextContentElement::GetSubStringLengthFuncNum: { ExceptionCode ec = 0; bool offsetOk; unsigned offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } bool lengthOk; unsigned length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = jsNumber(imp->getSubStringLength(offset, length, ec)); setDOMException(exec, ec); return result; } case JSSVGTextContentElement::GetStartPositionOfCharFuncNum: { ExceptionCode ec = 0; bool offsetOk; unsigned offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<FloatPoint>(imp->getStartPositionOfChar(offset, ec))); setDOMException(exec, ec); return result; } case JSSVGTextContentElement::GetEndPositionOfCharFuncNum: { ExceptionCode ec = 0; bool offsetOk; unsigned offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<FloatPoint>(imp->getEndPositionOfChar(offset, ec))); setDOMException(exec, ec); return result; } case JSSVGTextContentElement::GetExtentOfCharFuncNum: { ExceptionCode ec = 0; bool offsetOk; unsigned offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<FloatRect>(imp->getExtentOfChar(offset, ec))); setDOMException(exec, ec); return result; } case JSSVGTextContentElement::GetRotationOfCharFuncNum: { ExceptionCode ec = 0; bool offsetOk; unsigned offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = jsNumber(imp->getRotationOfChar(offset, ec)); setDOMException(exec, ec); return result; } case JSSVGTextContentElement::GetCharNumAtPositionFuncNum: { FloatPoint point = toSVGPoint(args[0]); KJS::JSValue* result = jsNumber(imp->getCharNumAtPosition(point)); return result; } case JSSVGTextContentElement::SelectSubStringFuncNum: { ExceptionCode ec = 0; bool offsetOk; unsigned offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } bool lengthOk; unsigned length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } imp->selectSubString(offset, length, ec); setDOMException(exec, ec); return jsUndefined(); } case JSSVGTextContentElement::HasExtensionFuncNum: { String extension = args[0]->toString(exec); KJS::JSValue* result = jsBoolean(imp->hasExtension(extension)); return result; } } return 0; }
JSValue JSWebKitSubtleCrypto::unwrapKey(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (state.argumentCount() < 5) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); CryptoKeyFormat keyFormat; auto success = cryptoKeyFormatFromJSValue(state, state.argument(0), keyFormat); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); CryptoOperationData wrappedKeyData; success = cryptoOperationDataFromJSValue(&state, state.uncheckedArgument(1), wrappedKeyData); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); RefPtr<CryptoKey> unwrappingKey = JSCryptoKey::toWrapped(state.uncheckedArgument(2)); if (!unwrappingKey) return throwTypeError(&state, scope); if (!unwrappingKey->allows(CryptoKeyUsageUnwrapKey)) { wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'unwrapKey'")); setDOMException(&state, NOT_SUPPORTED_ERR); return jsUndefined(); } auto unwrapAlgorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(3)); ASSERT(scope.exception() || unwrapAlgorithm); if (!unwrapAlgorithm) return jsUndefined(); auto unwrapAlgorithmParameters = JSCryptoAlgorithmDictionary::createParametersForDecrypt(&state, unwrapAlgorithm->identifier(), state.uncheckedArgument(3)); ASSERT(scope.exception() || unwrapAlgorithmParameters); if (!unwrapAlgorithmParameters) return jsUndefined(); RefPtr<CryptoAlgorithm> unwrappedKeyAlgorithm; RefPtr<CryptoAlgorithmParametersDeprecated> unwrappedKeyAlgorithmParameters; if (!state.uncheckedArgument(4).isNull()) { unwrappedKeyAlgorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(4)); ASSERT(scope.exception() || unwrappedKeyAlgorithm); if (!unwrappedKeyAlgorithm) return jsUndefined(); unwrappedKeyAlgorithmParameters = JSCryptoAlgorithmDictionary::createParametersForImportKey(&state, unwrappedKeyAlgorithm->identifier(), state.uncheckedArgument(4)); ASSERT(scope.exception() || unwrappedKeyAlgorithmParameters); if (!unwrappedKeyAlgorithmParameters) return jsUndefined(); } bool extractable = false; if (state.argumentCount() >= 6) { extractable = state.uncheckedArgument(5).toBoolean(&state); RETURN_IF_EXCEPTION(scope, JSValue()); } CryptoKeyUsageBitmap keyUsages = 0; if (state.argumentCount() >= 7) { auto success = cryptoKeyUsagesFromJSValue(state, state.argument(6), keyUsages); ASSERT(scope.exception() || success); if (!success) return jsUndefined(); } RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow()); auto promise = wrapper->promise(); Strong<JSDOMGlobalObject> domGlobalObject(state.vm(), globalObject()); auto decryptSuccessCallback = [domGlobalObject, keyFormat, unwrappedKeyAlgorithm, unwrappedKeyAlgorithmParameters, extractable, keyUsages, wrapper](const Vector<uint8_t>& result) mutable { auto importSuccessCallback = [wrapper](CryptoKey& key) mutable { wrapper->resolve(key); }; auto importFailureCallback = [wrapper]() mutable { wrapper->reject(nullptr); }; VM& vm = domGlobalObject->vm(); auto scope = DECLARE_CATCH_SCOPE(vm); ExecState& state = *domGlobalObject->globalExec(); WebCore::importKey(state, keyFormat, std::make_pair(result.data(), result.size()), unwrappedKeyAlgorithm, unwrappedKeyAlgorithmParameters, extractable, keyUsages, WTFMove(importSuccessCallback), WTFMove(importFailureCallback)); if (UNLIKELY(scope.exception())) { // FIXME: Report exception details to console, and possibly to calling script once there is a standardized way to pass errors to WebCrypto promise reject functions. scope.clearException(); wrapper->reject(nullptr); } }; auto decryptFailureCallback = [wrapper]() mutable { wrapper->reject(nullptr); }; auto result = unwrapAlgorithm->decryptForUnwrapKey(*unwrapAlgorithmParameters, *unwrappingKey, wrappedKeyData, WTFMove(decryptSuccessCallback), WTFMove(decryptFailureCallback)); if (result.hasException()) { propagateException(state, scope, result.releaseException()); return { }; } return promise; }
JSValue* JSHTMLFrameElement::getValueProperty(ExecState* exec, int token) const { switch (token) { case FrameBorderAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->frameBorder()); } case LongDescAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->longDesc()); } case MarginHeightAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->marginHeight()); } case MarginWidthAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->marginWidth()); } case NameAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->name()); } case NoResizeAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsBoolean(imp->noResize()); } case ScrollingAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->scrolling()); } case SrcAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->src()); } case ContentDocumentAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return checkNodeSecurity(exec, imp->contentDocument()) ? toJS(exec, WTF::getPtr(imp->contentDocument())) : jsUndefined(); } case ContentWindowAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return toJS(exec, WTF::getPtr(imp->contentWindow())); } case LocationAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsString(exec, imp->location()); } case WidthAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsNumber(exec, imp->width()); } case HeightAttrNum: { HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); return jsNumber(exec, imp->height()); } case ConstructorAttrNum: return getConstructor(exec); } return 0; }
JSValue JSNameScope::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode) { if (ecmaMode == StrictMode) return jsUndefined(); return exec->globalThisValue(); }
//-------------------------------------------------------------------------- // JSObjectKJSValue //-------------------------------------------------------------------------- JSValue* JSObjectKJSValue(JSUserObject* ptr) { JSLock lock(true); JSValue* result = jsUndefined(); if (ptr) { bool handled = false; switch (ptr->DataType()) { case kJSUserObjectDataTypeJSValueWrapper: { JSValueWrapper* wrapper = (JSValueWrapper*)ptr->GetData(); if (wrapper) { result = wrapper->GetValue(); handled = true; } break; } case kJSUserObjectDataTypeCFType: { CFTypeRef cfType = (CFTypeRef*)ptr->GetData(); if (cfType) { CFTypeID typeID = CFGetTypeID(cfType); if (typeID == CFStringGetTypeID()) { result = jsString(getThreadGlobalExecState(), CFStringToUString((CFStringRef)cfType)); handled = true; } else if (typeID == CFNumberGetTypeID()) { double num; CFNumberGetValue((CFNumberRef)cfType, kCFNumberDoubleType, &num); result = jsNumber(getThreadGlobalExecState(), num); handled = true; } else if (typeID == CFBooleanGetTypeID()) { result = jsBoolean(CFBooleanGetValue((CFBooleanRef)cfType)); handled = true; } else if (typeID == CFNullGetTypeID()) { result = jsNull(); handled = true; } } break; } } if (!handled) { ExecState* exec = getThreadGlobalExecState(); result = new (exec) UserObjectImp(getThreadGlobalObject()->userObjectStructure(), ptr); } } return result; }
static EncodedTiValue JSC_HOST_CALL callNativeErrorConstructor(TiExcState* exec) { TiValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); return TiValue::encode(ErrorInstance::create(exec, errorStructure, message)); }
static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) { if (exec->argumentCount() != 2) return throwSyntaxError(exec); if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info)) return throwTypeError(exec); WebGLUniformLocation* location = toWebGLUniformLocation(exec->argument(0)); if (exec->hadException()) return jsUndefined(); RefPtr<Int32Array> webGLArray = toInt32Array(exec->argument(1)); if (exec->hadException()) return jsUndefined(); ExceptionCode ec = 0; if (webGLArray) { switch (f) { case f_uniform1v: context->uniform1iv(location, webGLArray.get(), ec); break; case f_uniform2v: context->uniform2iv(location, webGLArray.get(), ec); break; case f_uniform3v: context->uniform3iv(location, webGLArray.get(), ec); break; case f_uniform4v: context->uniform4iv(location, webGLArray.get(), ec); break; default: break; } setDOMException(exec, ec); return jsUndefined(); } Vector<int, 64> array; if (!toVector(exec, exec->argument(1), array)) return throwTypeError(exec); switch (f) { case f_uniform1v: context->uniform1iv(location, array.data(), array.size(), ec); break; case f_uniform2v: context->uniform2iv(location, array.data(), array.size(), ec); break; case f_uniform3v: context->uniform3iv(location, array.data(), array.size(), ec); break; case f_uniform4v: context->uniform4iv(location, array.data(), array.size(), ec); break; default: break; } setDOMException(exec, ec); return jsUndefined(); }
EncodedJSValue JSC_HOST_CALL jsTestInterfaceConstructorFunctionSupplementalMethod4(ExecState* exec) { TestSupplemental::supplementalMethod4(); return JSValue::encode(jsUndefined()); }
void VariableEventStream::reconstruct( CodeBlock* codeBlock, CodeOrigin codeOrigin, MinifiedGraph& graph, unsigned index, Operands<ValueRecovery>& valueRecoveries) const { ASSERT(codeBlock->getJITType() == JITCode::DFGJIT); CodeBlock* baselineCodeBlock = codeBlock->baselineVersion(); unsigned numVariables; if (codeOrigin.inlineCallFrame) numVariables = baselineCodeBlockForInlineCallFrame(codeOrigin.inlineCallFrame)->m_numCalleeRegisters + codeOrigin.inlineCallFrame->stackOffset; else numVariables = baselineCodeBlock->m_numCalleeRegisters; // Crazy special case: if we're at index == 0 then this must be an argument check // failure, in which case all variables are already set up. The recoveries should // reflect this. if (!index) { valueRecoveries = Operands<ValueRecovery>(codeBlock->numParameters(), numVariables); for (size_t i = 0; i < valueRecoveries.size(); ++i) valueRecoveries[i] = ValueRecovery::alreadyInJSStack(); return; } // Step 1: Find the last checkpoint, and figure out the number of virtual registers as we go. unsigned startIndex = index - 1; while (at(startIndex).kind() != Reset) startIndex--; #if DFG_ENABLE(DEBUG_VERBOSE) dataLogF("Computing OSR exit recoveries starting at seq#%u.\n", startIndex); #endif // Step 2: Create a mock-up of the DFG's state and execute the events. Operands<ValueSource> operandSources(codeBlock->numParameters(), numVariables); Vector<MinifiedGenerationInfo, 32> generationInfos(graph.originalGraphSize()); for (unsigned i = startIndex; i < index; ++i) { const VariableEvent& event = at(i); switch (event.kind()) { case Reset: // nothing to do. break; case BirthToFill: case BirthToSpill: case Fill: case Spill: case Death: generationInfos[event.nodeIndex()].update(event); break; case MovHint: if (operandSources.hasOperand(event.operand())) operandSources.setOperand(event.operand(), ValueSource(event.nodeIndex())); break; case SetLocalEvent: if (operandSources.hasOperand(event.operand())) operandSources.setOperand(event.operand(), ValueSource::forDataFormat(event.dataFormat())); break; default: RELEASE_ASSERT_NOT_REACHED(); break; } } // Step 3: Record the things that are live, so we can get to them more quickly. Vector<unsigned, 16> indicesOfLiveThings; for (unsigned i = 0; i < generationInfos.size(); ++i) { if (generationInfos[i].format != DataFormatNone) indicesOfLiveThings.append(i); } // Step 4: Compute value recoveries! valueRecoveries = Operands<ValueRecovery>(codeBlock->numParameters(), numVariables); for (unsigned i = 0; i < operandSources.size(); ++i) { ValueSource& source = operandSources[i]; if (source.isTriviallyRecoverable()) { valueRecoveries[i] = source.valueRecovery(); continue; } ASSERT(source.kind() == HaveNode); MinifiedNode* node = graph.at(source.nodeIndex()); if (node) { if (node->hasConstantNumber()) { valueRecoveries[i] = ValueRecovery::constant( codeBlock->constantRegister( FirstConstantRegisterIndex + node->constantNumber()).get()); continue; } if (node->hasWeakConstant()) { valueRecoveries[i] = ValueRecovery::constant(node->weakConstant()); continue; } if (node->op() == PhantomArguments) { valueRecoveries[i] = ValueRecovery::argumentsThatWereNotCreated(); continue; } } MinifiedGenerationInfo* info = &generationInfos[source.nodeIndex()]; if (info->format == DataFormatNone) { // Try to see if there is an alternate node that would contain the value we want. // There are four possibilities: // // Int32ToDouble: We can use this in place of the original node, but // we'd rather not; so we use it only if it is the only remaining // live version. // // ValueToInt32: If the only remaining live version of the value is // ValueToInt32, then we can use it. // // UInt32ToNumber: If the only live version of the value is a UInt32ToNumber // then the only remaining uses are ones that want a properly formed number // rather than a UInt32 intermediate. // // DoubleAsInt32: Same as UInt32ToNumber. // // The reverse of the above: This node could be a UInt32ToNumber, but its // alternative is still alive. This means that the only remaining uses of // the number would be fine with a UInt32 intermediate. bool found = false; if (node && node->op() == UInt32ToNumber) { NodeIndex nodeIndex = node->child1(); node = graph.at(nodeIndex); info = &generationInfos[nodeIndex]; if (info->format != DataFormatNone) found = true; } if (!found) { NodeIndex int32ToDoubleIndex = NoNode; NodeIndex valueToInt32Index = NoNode; NodeIndex uint32ToNumberIndex = NoNode; NodeIndex doubleAsInt32Index = NoNode; for (unsigned i = 0; i < indicesOfLiveThings.size(); ++i) { NodeIndex nodeIndex = indicesOfLiveThings[i]; node = graph.at(nodeIndex); if (!node) continue; if (!node->hasChild1()) continue; if (node->child1() != source.nodeIndex()) continue; ASSERT(generationInfos[nodeIndex].format != DataFormatNone); switch (node->op()) { case Int32ToDouble: int32ToDoubleIndex = nodeIndex; break; case ValueToInt32: valueToInt32Index = nodeIndex; break; case UInt32ToNumber: uint32ToNumberIndex = nodeIndex; break; case DoubleAsInt32: doubleAsInt32Index = nodeIndex; break; default: break; } } NodeIndex nodeIndexToUse; if (doubleAsInt32Index != NoNode) nodeIndexToUse = doubleAsInt32Index; else if (int32ToDoubleIndex != NoNode) nodeIndexToUse = int32ToDoubleIndex; else if (valueToInt32Index != NoNode) nodeIndexToUse = valueToInt32Index; else if (uint32ToNumberIndex != NoNode) nodeIndexToUse = uint32ToNumberIndex; else nodeIndexToUse = NoNode; if (nodeIndexToUse != NoNode) { info = &generationInfos[nodeIndexToUse]; ASSERT(info->format != DataFormatNone); found = true; } } if (!found) { valueRecoveries[i] = ValueRecovery::constant(jsUndefined()); continue; } } ASSERT(info->format != DataFormatNone); if (info->filled) { if (info->format == DataFormatDouble) { valueRecoveries[i] = ValueRecovery::inFPR(info->u.fpr); continue; } #if USE(JSVALUE32_64) if (info->format & DataFormatJS) { valueRecoveries[i] = ValueRecovery::inPair(info->u.pair.tagGPR, info->u.pair.payloadGPR); continue; } #endif valueRecoveries[i] = ValueRecovery::inGPR(info->u.gpr, info->format); continue; } valueRecoveries[i] = ValueRecovery::displacedInJSStack(static_cast<VirtualRegister>(info->u.virtualReg), info->format); } // Step 5: Make sure that for locals that coincide with true call frame headers, the exit compiler knows // that those values don't have to be recovered. Signal this by using ValueRecovery::alreadyInJSStack() for (InlineCallFrame* inlineCallFrame = codeOrigin.inlineCallFrame; inlineCallFrame; inlineCallFrame = inlineCallFrame->caller.inlineCallFrame) { for (unsigned i = JSStack::CallFrameHeaderSize; i--;) valueRecoveries.setLocal(inlineCallFrame->stackOffset - i - 1, ValueRecovery::alreadyInJSStack()); } }
JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType) { RELEASE_ASSERT_NOT_REACHED(); return jsUndefined(); }
JSValue* JSCharacterDataPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { if (!thisObj->inherits(&JSCharacterData::info)) return throwError(exec, TypeError); CharacterData* imp = static_cast<CharacterData*>(static_cast<JSCharacterData*>(thisObj)->impl()); switch (id) { case JSCharacterData::SubstringDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } bool lengthOk; int length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (length < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } KJS::JSValue* result = jsStringOrNull(imp->substringData(offset, length, ec)); setDOMException(exec, ec); return result; } case JSCharacterData::AppendDataFuncNum: { ExceptionCode ec = 0; String data = args[0]->toString(exec); imp->appendData(data, ec); setDOMException(exec, ec); return jsUndefined(); } case JSCharacterData::InsertDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } String data = args[1]->toString(exec); imp->insertData(offset, data, ec); setDOMException(exec, ec); return jsUndefined(); } case JSCharacterData::DeleteDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } bool lengthOk; int length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (length < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } imp->deleteData(offset, length, ec); setDOMException(exec, ec); return jsUndefined(); } case JSCharacterData::ReplaceDataFuncNum: { ExceptionCode ec = 0; bool offsetOk; int offset = args[0]->toInt32(exec, offsetOk); if (!offsetOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (offset < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } bool lengthOk; int length = args[1]->toInt32(exec, lengthOk); if (!lengthOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } if (length < 0) { setDOMException(exec, INDEX_SIZE_ERR); return jsUndefined(); } String data = args[2]->toString(exec); imp->replaceData(offset, length, data, ec); setDOMException(exec, ec); return jsUndefined(); } } return 0; }
JSValue StrictEvalActivation::toThis(JSCell*, ExecState* exec, ECMAMode ecmaMode) { if (ecmaMode == StrictMode) return jsUndefined(); return exec->globalThisValue(); }
JSValue* JSSVGTransformListPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { if (!thisObj->inherits(&JSSVGTransformList::info)) return throwError(exec, TypeError); SVGTransformList* imp = static_cast<SVGTransformList*>(static_cast<JSSVGTransformList*>(thisObj)->impl()); switch (id) { case JSSVGTransformList::ClearFuncNum: { ExceptionCode ec = 0; imp->clear(ec); setDOMException(exec, ec); return jsUndefined(); } case JSSVGTransformList::InitializeFuncNum: { ExceptionCode ec = 0; SVGTransform item = toSVGTransform(args[0]); KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->initialize(item, ec))); setDOMException(exec, ec); return result; } case JSSVGTransformList::GetItemFuncNum: { ExceptionCode ec = 0; bool indexOk; unsigned index = args[0]->toInt32(exec, indexOk); if (!indexOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->getItem(index, ec))); setDOMException(exec, ec); return result; } case JSSVGTransformList::InsertItemBeforeFuncNum: { ExceptionCode ec = 0; SVGTransform item = toSVGTransform(args[0]); bool indexOk; unsigned index = args[1]->toInt32(exec, indexOk); if (!indexOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->insertItemBefore(item, index, ec))); setDOMException(exec, ec); return result; } case JSSVGTransformList::ReplaceItemFuncNum: { ExceptionCode ec = 0; SVGTransform item = toSVGTransform(args[0]); bool indexOk; unsigned index = args[1]->toInt32(exec, indexOk); if (!indexOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->replaceItem(item, index, ec))); setDOMException(exec, ec); return result; } case JSSVGTransformList::RemoveItemFuncNum: { ExceptionCode ec = 0; bool indexOk; unsigned index = args[0]->toInt32(exec, indexOk); if (!indexOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->removeItem(index, ec))); setDOMException(exec, ec); return result; } case JSSVGTransformList::AppendItemFuncNum: { ExceptionCode ec = 0; SVGTransform item = toSVGTransform(args[0]); KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->appendItem(item, ec))); setDOMException(exec, ec); return result; } case JSSVGTransformList::CreateSVGTransformFromMatrixFuncNum: { AffineTransform matrix = toSVGMatrix(args[0]); KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->createSVGTransformFromMatrix(matrix))); return result; } case JSSVGTransformList::ConsolidateFuncNum: { KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapper<SVGTransform>(imp->consolidate())); return result; } } return 0; }
static JSValue performPromiseAll(ExecState* exec, JSValue iterator, JSValue C, JSPromiseDeferred* deferred) { JSObject* thisObject = asObject(C); VM& vm = exec->vm(); // 6. Let 'values' be the result of calling ArrayCreate(0). JSArray* values = constructEmptyArray(exec, nullptr, thisObject->globalObject()); // 7. Let 'countdownHolder' be Record { [[Countdown]]: 0 }. NumberObject* countdownHolder = constructNumber(exec, thisObject->globalObject(), JSValue(0)); // 8. Let 'index' be 0. unsigned index = 0; // 9. Repeat. do { // i. Let 'next' be the result of calling IteratorStep(iterator). JSValue next = iteratorStep(exec, iterator); if (exec->hadException()) return jsUndefined(); // iii. If 'next' is false, if (next.isFalse()) { // a. If 'index' is 0, if (!index) { // a. Let 'resolveResult' be 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); // b. ReturnIfAbrupt(resolveResult). if (exec->hadException()) return jsUndefined(); } // b. Return deferred.[[Promise]]. return deferred->promise(); } // iv. Let 'nextValue' be the result of calling IteratorValue(next). // v. RejectIfAbrupt(nextValue, deferred). JSValue nextValue = iteratorValue(exec, next); if (exec->hadException()) return jsUndefined(); values->push(exec, jsUndefined()); // vi. Let 'nextPromise' be the result of calling Invoke(C, "resolve", (nextValue)). JSValue resolveFunction = C.get(exec, vm.propertyNames->resolve); if (exec->hadException()) return jsUndefined(); CallData resolveFunctionCallData; CallType resolveFunctionCallType = getCallData(resolveFunction, resolveFunctionCallData); if (resolveFunctionCallType == CallTypeNone) { throwTypeError(exec); return jsUndefined(); } MarkedArgumentBuffer resolveFunctionArguments; resolveFunctionArguments.append(nextValue); JSValue nextPromise = call(exec, resolveFunction, resolveFunctionCallType, resolveFunctionCallData, C, resolveFunctionArguments); // vii. RejectIfAbrupt(nextPromise, deferred). if (exec->hadException()) return jsUndefined(); // viii. Let 'countdownFunction' be a new built-in function object as defined in Promise.all Countdown Functions. JSFunction* countdownFunction = createPromiseAllCountdownFunction(vm, thisObject->globalObject()); // ix. Set the [[Index]] internal slot of 'countdownFunction' to 'index'. countdownFunction->putDirect(vm, vm.propertyNames->indexPrivateName, JSValue(index)); // x. Set the [[Values]] internal slot of 'countdownFunction' to 'values'. countdownFunction->putDirect(vm, vm.propertyNames->valuesPrivateName, values); // xi. Set the [[Deferred]] internal slot of 'countdownFunction' to 'deferred'. countdownFunction->putDirect(vm, vm.propertyNames->deferredPrivateName, deferred); // xii. Set the [[CountdownHolder]] internal slot of 'countdownFunction' to 'countdownHolder'. countdownFunction->putDirect(vm, vm.propertyNames->countdownHolderPrivateName, countdownHolder); // xiii. Let 'result' be the result of calling Invoke(nextPromise, "then", (countdownFunction, deferred.[[Reject]])). JSValue thenFunction = nextPromise.get(exec, vm.propertyNames->then); if (exec->hadException()) return jsUndefined(); CallData thenFunctionCallData; CallType thenFunctionCallType = getCallData(thenFunction, thenFunctionCallData); if (thenFunctionCallType == CallTypeNone) { throwTypeError(exec); return jsUndefined(); } MarkedArgumentBuffer thenFunctionArguments; thenFunctionArguments.append(countdownFunction); thenFunctionArguments.append(deferred->reject()); call(exec, thenFunction, thenFunctionCallType, thenFunctionCallData, nextPromise, thenFunctionArguments); // xiv. RejectIfAbrupt(result, deferred). if (exec->hadException()) return jsUndefined(); // xv. Set index to index + 1. index++; // xvi. Set countdownHolder.[[Countdown]] to countdownHolder.[[Countdown]] + 1. uint32_t newCountdownValue = countdownHolder->internalValue().asUInt32() + 1; countdownHolder->setInternalValue(vm, JSValue(newCountdownValue)); } while (true); ASSERT_NOT_REACHED(); return jsUndefined(); }
JSObject* ProgramExecutable::initializeGlobalProperties(VM& vm, CallFrame* callFrame, JSScope* scope) { RELEASE_ASSERT(scope); JSGlobalObject* globalObject = scope->globalObject(); RELEASE_ASSERT(globalObject); ASSERT(&globalObject->vm() == &vm); JSObject* exception = 0; UnlinkedProgramCodeBlock* unlinkedCodeBlock = globalObject->createProgramCodeBlock(callFrame, this, &exception); if (exception) return exception; JSGlobalLexicalEnvironment* globalLexicalEnvironment = globalObject->globalLexicalEnvironment(); const VariableEnvironment& variableDeclarations = unlinkedCodeBlock->variableDeclarations(); const VariableEnvironment& lexicalDeclarations = unlinkedCodeBlock->lexicalDeclarations(); // The ES6 spec says that no vars/global properties/let/const can be duplicated in the global scope. // This carried out section 15.1.8 of the ES6 spec: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-globaldeclarationinstantiation { ExecState* exec = globalObject->globalExec(); // Check for intersection of "var" and "let"/"const"/"class" for (auto& entry : lexicalDeclarations) { if (variableDeclarations.contains(entry.key)) return createSyntaxError(exec, makeString("Can't create duplicate variable: '", String(entry.key.get()), "'")); } // Check if any new "let"/"const"/"class" will shadow any pre-existing global property names, or "var"/"let"/"const" variables. // It's an error to introduce a shadow. for (auto& entry : lexicalDeclarations) { if (globalObject->hasProperty(exec, entry.key.get())) { // The ES6 spec says that just RestrictedGlobalProperty can't be shadowed // This carried out section 8.1.1.4.14 of the ES6 spec: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasrestrictedglobalproperty PropertyDescriptor descriptor; globalObject->getOwnPropertyDescriptor(exec, entry.key.get(), descriptor); if (descriptor.value() != jsUndefined() && !descriptor.configurable()) return createSyntaxError(exec, makeString("Can't create duplicate variable that shadows a global property: '", String(entry.key.get()), "'")); } if (globalLexicalEnvironment->hasProperty(exec, entry.key.get())) { if (UNLIKELY(entry.value.isConst() && !vm.globalConstRedeclarationShouldThrow() && !isStrictMode())) { // We only allow "const" duplicate declarations under this setting. // For example, we don't "let" variables to be overridden by "const" variables. if (globalLexicalEnvironment->isConstVariable(entry.key.get())) continue; } return createSyntaxError(exec, makeString("Can't create duplicate variable: '", String(entry.key.get()), "'")); } } // Check if any new "var"s will shadow any previous "let"/"const"/"class" names. // It's an error to introduce a shadow. if (!globalLexicalEnvironment->isEmpty()) { for (auto& entry : variableDeclarations) { if (globalLexicalEnvironment->hasProperty(exec, entry.key.get())) return createSyntaxError(exec, makeString("Can't create duplicate variable: '", String(entry.key.get()), "'")); } } } m_unlinkedProgramCodeBlock.set(vm, this, unlinkedCodeBlock); BatchedTransitionOptimizer optimizer(vm, globalObject); for (size_t i = 0, numberOfFunctions = unlinkedCodeBlock->numberOfFunctionDecls(); i < numberOfFunctions; ++i) { UnlinkedFunctionExecutable* unlinkedFunctionExecutable = unlinkedCodeBlock->functionDecl(i); ASSERT(!unlinkedFunctionExecutable->name().isEmpty()); globalObject->addFunction(callFrame, unlinkedFunctionExecutable->name()); if (vm.typeProfiler() || vm.controlFlowProfiler()) { vm.functionHasExecutedCache()->insertUnexecutedRange(sourceID(), unlinkedFunctionExecutable->typeProfilingStartOffset(), unlinkedFunctionExecutable->typeProfilingEndOffset()); } } for (auto& entry : variableDeclarations) { ASSERT(entry.value.isVar()); globalObject->addVar(callFrame, Identifier::fromUid(&vm, entry.key.get())); } { JSGlobalLexicalEnvironment* globalLexicalEnvironment = jsCast<JSGlobalLexicalEnvironment*>(globalObject->globalScope()); SymbolTable* symbolTable = globalLexicalEnvironment->symbolTable(); ConcurrentJITLocker locker(symbolTable->m_lock); for (auto& entry : lexicalDeclarations) { if (UNLIKELY(entry.value.isConst() && !vm.globalConstRedeclarationShouldThrow() && !isStrictMode())) { if (symbolTable->contains(locker, entry.key.get())) continue; } ScopeOffset offset = symbolTable->takeNextScopeOffset(locker); SymbolTableEntry newEntry(VarOffset(offset), entry.value.isConst() ? ReadOnly : 0); newEntry.prepareToWatch(); symbolTable->add(locker, entry.key.get(), newEntry); ScopeOffset offsetForAssert = globalLexicalEnvironment->addVariables(1, jsTDZValue()); RELEASE_ASSERT(offsetForAssert == offset); } } return 0; }
JSValue JSDOMWindow::sharedWorker(ExecState* exec) const { if (SharedWorkerRepository::isAvailable()) return getDOMConstructor<JSSharedWorkerConstructor>(exec, this); return jsUndefined(); }