JSValue JSNode::replaceChild(ExecState* exec) { Node* imp = static_cast<Node*>(impl()); ExceptionCode ec = 0; bool ok = imp->replaceChild(toNode(exec->argument(0)), toNode(exec->argument(1)), ec, true); setDOMException(exec, ec); if (ok) return exec->argument(1); return jsNull(); }
boost::shared_array<char> Document::write(ULONG *outLength) const { ULONG totalSize = Parser::getOutputSize(mThis.lock(), toNode()); boost::shared_array<char> buffer(new char[totalSize+1]); char *pos = buffer.get(); Parser::writeBuffer(mThis.lock(), toNode(), pos); *pos = 0; if (NULL != outLength) *outLength = totalSize; return buffer; }
bool EventTarget::addEventListenerInternal(const AtomicString& eventType, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions& options) { if (!listener) return false; V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld(); if (activityLogger) { Vector<String> argv; argv.append(toNode() ? toNode()->nodeName() : interfaceName()); argv.append(eventType); activityLogger->logEvent("blinkAddEventListener", argv.size(), argv.data()); } return ensureEventTargetData().eventListenerMap.add(eventType, listener, options); }
JSValue JSNode::replaceChild(ExecState* exec, const ArgList& args) { Node* imp = static_cast<Node*>(impl()); if (imp->nodeType() == Node::ATTRIBUTE_NODE && isAttrFrameSrc(static_cast<Attr*>(impl())->ownerElement(), imp->nodeName())) { setDOMException(exec, NOT_SUPPORTED_ERR); return jsNull(); } ExceptionCode ec = 0; bool ok = imp->replaceChild(toNode(args.at(0)), toNode(args.at(1)), ec, true); setDOMException(exec, ec); if (ok) return args.at(1); return jsNull(); }
JSValue* jsXPathEvaluatorPrototypeFunctionEvaluate(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSXPathEvaluator::s_info)) return throwError(exec, TypeError); JSXPathEvaluator* castedThisObj = static_cast<JSXPathEvaluator*>(thisValue); XPathEvaluator* imp = static_cast<XPathEvaluator*>(castedThisObj->impl()); ExceptionCode ec = 0; const UString& expression = args[0]->toString(exec); Node* contextNode = toNode(args[1]); RefPtr<XPathNSResolver> customResolver; XPathNSResolver* resolver = toXPathNSResolver(args[2]); if (!resolver) { customResolver = JSCustomXPathNSResolver::create(exec, args[2]); if (exec->hadException()) return jsUndefined(); resolver = customResolver.get(); } unsigned short type = args[3]->toInt32(exec); XPathResult* inResult = toXPathResult(args[4]); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->evaluate(expression, contextNode, resolver, type, inResult, ec))); setDOMException(exec, ec); return result; }
void Node::adoptAsLastChild(NodePtr inNode) { if (!inNode) return; // first the node has to be orphaned inNode->orphan(); // adopt this as the parent inNode->mParent = toNode(); // point existing last child's next sibling to new node if (mLastChild) mLastChild->mNextSibling = inNode; // point new node's previous sibling to current last child inNode->mPreviousSibling = mLastChild; // first child is now new node mLastChild = inNode; // if there wasn't a last child then it is now pointing to the new node if (!mFirstChild) mFirstChild = inNode; }
JSValue JSCommandLineAPIHost::getEventListeners(ExecState* exec) { if (exec->argumentCount() < 1) return jsUndefined(); JSValue value = exec->uncheckedArgument(0); if (!value.isObject() || value.isNull()) return jsUndefined(); Node* node = toNode(value); if (!node) return jsUndefined(); Vector<EventListenerInfo> listenersArray; impl().getEventListenersImpl(node, listenersArray); JSObject* result = constructEmptyObject(exec); for (size_t i = 0; i < listenersArray.size(); ++i) { JSArray* listeners = getJSListenerFunctions(exec, &node->document(), listenersArray[i]); if (!listeners->length()) continue; AtomicString eventType = listenersArray[i].eventType; result->putDirect(exec->vm(), Identifier(exec, eventType.impl()), JSValue(listeners)); } return result; }
void Node::adoptAsNextSibling(NodePtr inNode) { if (!inNode) return; NodePtr parent = mParent.lock(); ZS_THROW_INVALID_USAGE_IF(!parent) // you cannot add as a sibling if there is no parent // orphan the node first inNode->orphan(); // nodes both share the same parent inNode->mParent = mParent; inNode->mPreviousSibling = toNode(); inNode->mNextSibling = mNextSibling; if (mNextSibling) mNextSibling->mPreviousSibling = inNode; mNextSibling = inNode; if (parent->mLastChild.get() == this) parent->mLastChild = inNode; }
JSValue JSInjectedScriptHost::getEventListeners(ExecState* exec) { if (exec->argumentCount() < 1) return jsUndefined(); JSValue value = exec->argument(0); if (!value.isObject() || value.isNull()) return jsUndefined(); Node* node = toNode(value); if (!node) return jsUndefined(); // This can only happen for orphan DocumentType nodes. Document* document = node->document(); if (!node->document()) return jsUndefined(); Vector<EventListenerInfo> listenersArray; impl()->getEventListenersImpl(node, listenersArray); JSObject* result = constructEmptyObject(exec); for (size_t i = 0; i < listenersArray.size(); ++i) { JSArray* listeners = getJSListenerFunctions(exec, document, listenersArray[i]); if (!listeners->length()) continue; AtomicString eventType = listenersArray[i].eventType; result->putDirect(exec->globalData(), Identifier(exec, eventType.impl()), JSValue(listeners)); } return result; }
JSValue JSInspectorFrontendHost::search(ExecState* exec, const ArgList& args) { if (args.size() < 2) return jsUndefined(); Node* node = toNode(args.at(0)); if (!node) return jsUndefined(); String target = args.at(1).toString(exec); if (exec->hadException()) return jsUndefined(); MarkedArgumentBuffer result; RefPtr<Range> searchRange(rangeOfContents(node)); ExceptionCode ec = 0; do { RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, false)); if (resultRange->collapsed(ec)) break; // A non-collapsed result range can in some funky whitespace cases still not // advance the range's start position (4509328). Break to avoid infinite loop. VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM); if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM)) break; result.append(toJS(exec, resultRange.get())); setStart(searchRange.get(), newStart); } while (true); return constructArray(exec, result); }
EncodedJSValue JSC_HOST_CALL jsXPathEvaluatorPrototypeFunctionEvaluate(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSXPathEvaluator::s_info)) return throwVMTypeError(exec); JSXPathEvaluator* castedThis = static_cast<JSXPathEvaluator*>(asObject(thisValue)); XPathEvaluator* imp = static_cast<XPathEvaluator*>(castedThis->impl()); ExceptionCode ec = 0; const String& expression(ustringToString(exec->argument(0).toString(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); Node* contextNode(toNode(exec->argument(1))); if (exec->hadException()) return JSValue::encode(jsUndefined()); RefPtr<XPathNSResolver> customResolver; XPathNSResolver* resolver = toXPathNSResolver(exec->argument(2)); if (!resolver) { customResolver = JSCustomXPathNSResolver::create(exec, exec->argument(2)); if (exec->hadException()) return JSValue::encode(jsUndefined()); resolver = customResolver.get(); } unsigned short type(exec->argument(3).toUInt32(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); XPathResult* inResult(toXPathResult(exec->argument(4))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->evaluate(expression, contextNode, resolver, type, inResult, ec))); setDOMException(exec, ec); return JSValue::encode(result); }
void HandleSet::writeBarrier(HandleSlot slot, const JSValue& value) { // Forbid assignment to handles during the finalization phase, since it would violate many GC invariants. // File a bug with stack trace if you hit this. if (m_nextToFinalize) CRASH(); if (!value == !*slot && slot->isCell() == value.isCell()) return; Node* node = toNode(slot); #if ENABLE(GC_VALIDATION) if (!isLiveNode(node)) CRASH(); #endif SentinelLinkedList<Node>::remove(node); if (!value || !value.isCell()) { m_immediateList.push(node); return; } m_strongList.push(node); #if ENABLE(GC_VALIDATION) if (!isLiveNode(node)) CRASH(); #endif }
EncodedJSValue JSC_HOST_CALL jsXPathEvaluatorPrototypeFunctionEvaluate(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSXPathEvaluator* castedThis = jsDynamicCast<JSXPathEvaluator*>(thisValue); if (!castedThis) return throwVMTypeError(exec); ASSERT_GC_OBJECT_INHERITS(castedThis, JSXPathEvaluator::info()); XPathEvaluator& impl = castedThis->impl(); ExceptionCode ec = 0; const String& expression(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); Node* contextNode(toNode(exec->argument(1))); if (exec->hadException()) return JSValue::encode(jsUndefined()); RefPtr<XPathNSResolver> customResolver; XPathNSResolver* resolver = toXPathNSResolver(exec->argument(2)); if (!resolver) { customResolver = JSCustomXPathNSResolver::create(exec, exec->argument(2)); if (exec->hadException()) return JSValue::encode(jsUndefined()); resolver = customResolver.get(); } uint16_t type(toUInt16(exec, exec->argument(3), NormalConversion)); if (exec->hadException()) return JSValue::encode(jsUndefined()); XPathResult* inResult(toXPathResult(exec->argument(4))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.evaluate(expression, contextNode, resolver, type, inResult, ec))); setDOMException(exec, ec); return JSValue::encode(result); }
NodePtr Node::getLastSibling() const { NodePtr parent = getParent(); if (parent) return parent->getLastChild(); return toNode(); }
bool EventTarget::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture) { // FIXME: listener null check should throw TypeError (and be done in // generated bindings), but breaks legacy content. http://crbug.com/249598 if (!listener) return false; V8DOMActivityLogger* activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld(); if (activityLogger) { Vector<String> argv; argv.append(toNode() ? toNode()->nodeName() : interfaceName()); argv.append(eventType); activityLogger->logEvent("blinkAddEventListener", argv.size(), argv.data()); } return ensureEventTargetData().eventListenerMap.add(eventType, listener, useCapture); }
JSValue* JSNodeFilter::acceptNode(ExecState* exec, const ArgList& args) { JSValue* exception = 0; short result = impl()->acceptNode(toNode(args[0]), exception); if (exception) exec->setException(exception); return jsNumber(exec, result); }
JSValuePtr JSNode::appendChild(ExecState* exec, const ArgList& args) { ExceptionCode ec = 0; bool ok = impl()->appendChild(toNode(args.at(exec, 0)), ec, true); setDOMException(exec, ec); if (ok) return args.at(exec, 0); return jsNull(); }
JSValue JSNode::removeChild(ExecState* exec, const ArgList& args) { ExceptionCode ec = 0; bool ok = impl()->removeChild(toNode(args.at(0)), ec); setDOMException(exec, ec); if (ok) return args.at(0); return jsNull(); }
void setJSTestInterfaceSupplementalNode(ExecState* exec, JSObject* thisObject, JSValue value) { UNUSED_PARAM(exec); JSTestInterface* castedThis = jsCast<JSTestInterface*>(thisObject); TestInterface* impl = static_cast<TestInterface*>(castedThis->impl()); Node* nativeValue(toNode(value)); if (exec->hadException()) return; TestSupplemental::setSupplementalNode(impl, nativeValue); }
void setJSTestInterfaceImplementsNode(ExecState* exec, JSObject* thisObject, JSValue value) { UNUSED_PARAM(exec); JSTestInterface* castedThis = jsCast<JSTestInterface*>(thisObject); TestInterface& impl = castedThis->impl(); Node* nativeValue(toNode(value)); if (exec->hadException()) return; impl.setImplementsNode(nativeValue); }
NodePtr Node::getRoot() const { NodePtr found = toNode(); NodePtr parent = found->getParent(); while (parent) { found = parent; parent = parent->getParent(); } return found; }
JSValue* jsNodePrototypeFunctionIsEqualNode(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSNode::s_info)) return throwError(exec, TypeError); JSNode* castedThisObj = static_cast<JSNode*>(thisValue); Node* imp = static_cast<Node*>(castedThisObj->impl()); Node* other = toNode(args[0]); KJS::JSValue* result = jsBoolean(imp->isEqualNode(other)); return result; }
void JSTreeWalker::putValueProperty(ExecState* exec, int token, JSValue* value) { switch (token) { case CurrentNodeAttrNum: { TreeWalker* imp = static_cast<TreeWalker*>(impl()); ExceptionCode ec = 0; imp->setCurrentNode(toNode(value), ec); setDOMException(exec, ec); break; } } }
JSValue* jsXPathEvaluatorPrototypeFunctionCreateNSResolver(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSXPathEvaluator::s_info)) return throwError(exec, TypeError); JSXPathEvaluator* castedThisObj = static_cast<JSXPathEvaluator*>(thisValue); XPathEvaluator* imp = static_cast<XPathEvaluator*>(castedThisObj->impl()); Node* nodeResolver = toNode(args[0]); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createNSResolver(nodeResolver))); return result; }
JSValue JSInjectedScriptHost::pushNodePathToFrontend(ExecState* exec, const ArgList& args) { if (args.size() < 3) return jsUndefined(); Node* node = toNode(args.at(0)); if (!node) return jsUndefined(); bool withChildren = args.at(1).toBoolean(exec); bool selectInUI = args.at(2).toBoolean(exec); return jsNumber(exec, impl()->pushNodePathToFrontend(node, withChildren, selectInUI)); }
JSValue* jsRangePrototypeFunctionSurroundContents(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSRange::s_info)) return throwError(exec, TypeError); JSRange* castedThisObj = static_cast<JSRange*>(thisValue); Range* imp = static_cast<Range*>(castedThisObj->impl()); ExceptionCode ec = 0; Node* newParent = toNode(args[0]); imp->surroundContents(newParent, ec); setDOMException(exec, ec); return jsUndefined(); }
JSValue JSInjectedScriptHost::pushNodePathToFrontend(ExecState* exec) { if (exec->argumentCount() < 3) return jsUndefined(); Node* node = toNode(exec->argument(0)); if (!node) return jsUndefined(); bool withChildren = exec->argument(1).toBoolean(exec); bool selectInUI = exec->argument(2).toBoolean(exec); return jsNumber(impl()->pushNodePathToFrontend(node, withChildren, selectInUI)); }
static JSValueRef search(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) { InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject)); if (!controller) return JSValueMakeUndefined(ctx); if (argumentCount < 2 || !JSValueIsString(ctx, arguments[1])) return JSValueMakeUndefined(ctx); Node* node = toNode(toJS(arguments[0])); if (!node) return JSValueMakeUndefined(ctx); JSStringRef string = JSValueToStringCopy(ctx, arguments[1], 0); String target(JSStringGetCharactersPtr(string), JSStringGetLength(string)); JSStringRelease(string); JSObjectRef globalObject = JSContextGetGlobalObject(ctx); JSStringRef constructorString = JSStringCreateWithUTF8CString("Array"); JSObjectRef arrayConstructor = JSValueToObject(ctx, JSObjectGetProperty(ctx, globalObject, constructorString, 0), 0); JSStringRelease(constructorString); JSObjectRef array = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, 0); JSStringRef pushString = JSStringCreateWithUTF8CString("push"); JSValueRef pushValue = JSObjectGetProperty(ctx, array, pushString, 0); JSStringRelease(pushString); JSObjectRef push = JSValueToObject(ctx, pushValue, 0); RefPtr<Range> searchRange(rangeOfContents(node)); int exception = 0; do { RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, false)); if (resultRange->collapsed(exception)) break; // A non-collapsed result range can in some funky whitespace cases still not // advance the range's start position (4509328). Break to avoid infinite loop. VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM); if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM)) break; KJS::JSLock lock; JSValueRef arg0 = toRef(toJS(toJS(ctx), resultRange.get())); JSObjectCallAsFunction(ctx, push, array, 1, &arg0, 0); setStart(searchRange.get(), newStart); } while (true); return array; }
JSValue* jsRangePrototypeFunctionCompareNode(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSRange::s_info)) return throwError(exec, TypeError); JSRange* castedThisObj = static_cast<JSRange*>(thisValue); Range* imp = static_cast<Range*>(castedThisObj->impl()); ExceptionCode ec = 0; Node* refNode = toNode(args[0]); KJS::JSValue* result = jsNumber(exec, imp->compareNode(refNode, ec)); setDOMException(exec, ec); return result; }
JSValue* jsRangePrototypeFunctionSetEnd(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSRange::s_info)) return throwError(exec, TypeError); JSRange* castedThisObj = static_cast<JSRange*>(thisValue); Range* imp = static_cast<Range*>(castedThisObj->impl()); ExceptionCode ec = 0; Node* refNode = toNode(args[0]); int offset = args[1]->toInt32(exec); imp->setEnd(refNode, offset, ec); setDOMException(exec, ec); return jsUndefined(); }