📄 jsdombinding.cpp
字号:
JSNode* jsNode = nodeIt->second; Node* node = jsNode->impl(); if (jsNode->marked()) continue; // No need to preserve a wrapper that has no custom properties or is no // longer fetchable through the DOM. if (!jsNode->hasCustomProperties() || !node->inDocument()) { //... unless the wrapper wraps a loading image, since the "new Image" // syntax allows an orphan image wrapper to be the last reference // to a loading image, whose load event might have important side-effects. if (!node->hasTagName(imgTag) || static_cast<HTMLImageElement*>(node)->haveFiredLoadEvent()) continue; } jsNode->mark(); }}void markActiveObjectsForContext(JSGlobalData& globalData, ScriptExecutionContext* scriptExecutionContext){ // If an element has pending activity that may result in event listeners being called // (e.g. an XMLHttpRequest), we need to keep JS wrappers alive. const HashMap<ActiveDOMObject*, void*>& activeObjects = scriptExecutionContext->activeDOMObjects(); HashMap<ActiveDOMObject*, void*>::const_iterator activeObjectsEnd = activeObjects.end(); for (HashMap<ActiveDOMObject*, void*>::const_iterator iter = activeObjects.begin(); iter != activeObjectsEnd; ++iter) { if (iter->first->hasPendingActivity()) { DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, iter->second); // Generally, an active object with pending activity must have a wrapper to mark its listeners. // However, some ActiveDOMObjects don't have JS wrappers (timers created by setTimeout is one example). // FIXME: perhaps need to make sure even timers have a markable 'wrapper'. if (wrapper && !wrapper->marked()) wrapper->mark(); } } const HashSet<MessagePort*>& messagePorts = scriptExecutionContext->messagePorts(); HashSet<MessagePort*>::const_iterator portsEnd = messagePorts.end(); for (HashSet<MessagePort*>::const_iterator iter = messagePorts.begin(); iter != portsEnd; ++iter) { if ((*iter)->hasPendingActivity()) { DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, *iter); // A port with pending activity must have a wrapper to mark its listeners, so no null check. if (!wrapper->marked()) wrapper->mark(); } }}void updateDOMNodeDocument(Node* node, Document* oldDocument, Document* newDocument){ ASSERT(oldDocument != newDocument); JSNode* wrapper = getCachedDOMNodeWrapper(oldDocument, node); if (!wrapper) return; removeWrapper(wrapper); cacheDOMNodeWrapper(newDocument, node, wrapper); forgetDOMNode(oldDocument, node); addWrapper(wrapper);}void markDOMObjectWrapper(JSGlobalData& globalData, void* object){ if (!object) return; DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, object); if (!wrapper || wrapper->marked()) return; wrapper->mark();}JSValuePtr jsStringOrNull(ExecState* exec, const String& s){ if (s.isNull()) return jsNull(); return jsString(exec, s);}JSValuePtr jsOwnedStringOrNull(ExecState* exec, const UString& s){ if (s.isNull()) return jsNull(); return jsOwnedString(exec, s);}JSValuePtr jsStringOrUndefined(ExecState* exec, const String& s){ if (s.isNull()) return jsUndefined(); return jsString(exec, s);}JSValuePtr jsStringOrFalse(ExecState* exec, const String& s){ if (s.isNull()) return jsBoolean(false); return jsString(exec, s);}JSValuePtr jsStringOrNull(ExecState* exec, const KURL& url){ if (url.isNull()) return jsNull(); return jsString(exec, url.string());}JSValuePtr jsStringOrUndefined(ExecState* exec, const KURL& url){ if (url.isNull()) return jsUndefined(); return jsString(exec, url.string());}JSValuePtr jsStringOrFalse(ExecState* exec, const KURL& url){ if (url.isNull()) return jsBoolean(false); return jsString(exec, url.string());}UString valueToStringWithNullCheck(ExecState* exec, JSValuePtr value){ if (value.isNull()) return UString(); return value.toString(exec);}UString valueToStringWithUndefinedOrNullCheck(ExecState* exec, JSValuePtr value){ if (value.isUndefinedOrNull()) return UString(); return value.toString(exec);}void reportException(JSC::ExecState* exec, JSValuePtr exception){ UString errorMessage = exception.toString(exec); JSObject* exceptionObject = exception.toObject(exec); int lineNumber = exceptionObject->get(exec, Identifier(exec, "line")).toInt32(exec); UString exceptionSourceURL = exceptionObject->get(exec, Identifier(exec, "sourceURL")).toString(exec); exec->clearException(); ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); scriptExecutionContext->reportException(errorMessage, lineNumber, exceptionSourceURL);}void reportCurrentException(JSC::ExecState* exec){ JSValuePtr exception = exec->exception(); exec->clearException(); reportException(exec, exception);}void setDOMException(ExecState* exec, ExceptionCode ec){ if (!ec || exec->hadException()) return; ExceptionCodeDescription description; getExceptionCodeDescription(ec, description); JSValuePtr errorObject = noValue(); switch (description.type) { case DOMExceptionType: errorObject = toJS(exec, DOMCoreException::create(description)); break; case RangeExceptionType: errorObject = toJS(exec, RangeException::create(description)); break; case EventExceptionType: errorObject = toJS(exec, EventException::create(description)); break; case XMLHttpRequestExceptionType: errorObject = toJS(exec, XMLHttpRequestException::create(description)); break;#if ENABLE(SVG) case SVGExceptionType: errorObject = toJS(exec, SVGException::create(description).get(), 0); break;#endif#if ENABLE(XPATH) case XPathExceptionType: errorObject = toJS(exec, XPathException::create(description)); break;#endif } ASSERT(errorObject); exec->setException(errorObject);}bool checkNodeSecurity(ExecState* exec, Node* node){ return node && allowsAccessFromFrame(exec, node->document()->frame());}bool allowsAccessFromFrame(ExecState* exec, Frame* frame){ if (!frame) return false; JSDOMWindow* window = toJSDOMWindow(frame); return window && window->allowsAccessFrom(exec);}bool allowsAccessFromFrame(ExecState* exec, Frame* frame, String& message){ if (!frame) return false; JSDOMWindow* window = toJSDOMWindow(frame); return window && window->allowsAccessFrom(exec, message);}void printErrorMessageForFrame(Frame* frame, const String& message){ if (!frame) return; if (JSDOMWindow* window = toJSDOMWindow(frame)) window->printErrorMessage(message);}JSValuePtr objectToStringFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&){ return new (exec) PrototypeFunction(exec, 0, propertyName, objectProtoFuncToString);}ScriptState* scriptStateFromNode(Node* node){ if (!node) return 0; Document* document = node->document(); if (!document) return 0; Frame* frame = document->frame(); if (!frame) return 0; if (!frame->script()->isEnabled()) return 0; return frame->script()->globalObject()->globalExec();}Structure* getCachedDOMStructure(ExecState* exec, const ClassInfo* classInfo){ JSDOMStructureMap& structures = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->structures(); return structures.get(classInfo).get();}Structure* cacheDOMStructure(ExecState* exec, PassRefPtr<Structure> structure, const ClassInfo* classInfo){ JSDOMStructureMap& structures = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->structures(); ASSERT(!structures.contains(classInfo)); return structures.set(classInfo, structure).first->second.get();}JSObject* getCachedDOMConstructor(ExecState* exec, const ClassInfo* classInfo){ JSDOMConstructorMap& constructors = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->constructors(); return constructors.get(classInfo);}void cacheDOMConstructor(ExecState* exec, const ClassInfo* classInfo, JSObject* constructor){ JSDOMConstructorMap& constructors = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->constructors(); ASSERT(!constructors.contains(classInfo)); constructors.set(classInfo, constructor);}} // namespace WebCore
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -