1 /*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "config.h"
22 #include "JSDOMBinding.h"
23
24 #include "ActiveDOMObject.h"
25 #include "DOMCoreException.h"
26 #include "Document.h"
27 #include "EventException.h"
28 #include "ExceptionCode.h"
29 #include "Frame.h"
30 #include "HTMLAudioElement.h"
31 #include "HTMLImageElement.h"
32 #include "HTMLScriptElement.h"
33 #include "HTMLNames.h"
34 #include "JSDOMCoreException.h"
35 #include "JSDOMWindowCustom.h"
36 #include "JSEventException.h"
37 #include "JSNode.h"
38 #include "JSRangeException.h"
39 #include "JSXMLHttpRequestException.h"
40 #include "KURL.h"
41 #include "MessagePort.h"
42 #include "RangeException.h"
43 #include "ScriptController.h"
44 #include "XMLHttpRequestException.h"
45 #include <runtime/PrototypeFunction.h>
46 #include <wtf/StdLibExtras.h>
47
48 #if ENABLE(SVG)
49 #include "JSSVGException.h"
50 #include "SVGException.h"
51 #endif
52
53 #if ENABLE(XPATH)
54 #include "JSXPathException.h"
55 #include "XPathException.h"
56 #endif
57
58 #if ENABLE(WORKERS)
59 #include <wtf/ThreadSpecific.h>
60 using namespace WTF;
61 #endif
62
63 using namespace JSC;
64
65 namespace WebCore {
66
67 using namespace HTMLNames;
68
69 typedef Document::JSWrapperCache JSWrapperCache;
70
71 // For debugging, keep a set of wrappers currently registered, and check that
72 // all are unregistered before they are destroyed. This has helped us fix at
73 // least one bug.
74
75 static void addWrapper(DOMObject* wrapper);
76 static void removeWrapper(DOMObject* wrapper);
77 static void removeWrappers(const JSWrapperCache& wrappers);
78
79 #ifdef NDEBUG
80
addWrapper(DOMObject *)81 static inline void addWrapper(DOMObject*)
82 {
83 }
84
removeWrapper(DOMObject *)85 static inline void removeWrapper(DOMObject*)
86 {
87 }
88
removeWrappers(const JSWrapperCache &)89 static inline void removeWrappers(const JSWrapperCache&)
90 {
91 }
92
93 #else
94
wrapperSet()95 static HashSet<DOMObject*>& wrapperSet()
96 {
97 #if ENABLE(WORKERS)
98 DEFINE_STATIC_LOCAL(ThreadSpecific<HashSet<DOMObject*> >, staticWrapperSet, ());
99 return *staticWrapperSet;
100 #else
101 DEFINE_STATIC_LOCAL(HashSet<DOMObject*>, staticWrapperSet, ());
102 return staticWrapperSet;
103 #endif
104 }
105
addWrapper(DOMObject * wrapper)106 static void addWrapper(DOMObject* wrapper)
107 {
108 ASSERT(!wrapperSet().contains(wrapper));
109 wrapperSet().add(wrapper);
110 }
111
removeWrapper(DOMObject * wrapper)112 static void removeWrapper(DOMObject* wrapper)
113 {
114 if (!wrapper)
115 return;
116 ASSERT(wrapperSet().contains(wrapper));
117 wrapperSet().remove(wrapper);
118 }
119
removeWrappers(const JSWrapperCache & wrappers)120 static void removeWrappers(const JSWrapperCache& wrappers)
121 {
122 for (JSWrapperCache::const_iterator it = wrappers.begin(); it != wrappers.end(); ++it)
123 removeWrapper(it->second);
124 }
125
~DOMObject()126 DOMObject::~DOMObject()
127 {
128 ASSERT(!wrapperSet().contains(this));
129 }
130
131 #endif
132
133 class DOMObjectWrapperMap {
134 public:
135 static DOMObjectWrapperMap& mapFor(JSGlobalData&);
136
get(void * objectHandle)137 DOMObject* get(void* objectHandle)
138 {
139 return m_map.get(objectHandle);
140 }
141
set(void * objectHandle,DOMObject * wrapper)142 void set(void* objectHandle, DOMObject* wrapper)
143 {
144 addWrapper(wrapper);
145 m_map.set(objectHandle, wrapper);
146 }
147
remove(void * objectHandle)148 void remove(void* objectHandle)
149 {
150 removeWrapper(m_map.take(objectHandle));
151 }
152
153 private:
154 HashMap<void*, DOMObject*> m_map;
155 };
156
157 // Map from static HashTable instances to per-GlobalData ones.
158 class DOMObjectHashTableMap {
159 public:
160 static DOMObjectHashTableMap& mapFor(JSGlobalData&);
161
~DOMObjectHashTableMap()162 ~DOMObjectHashTableMap()
163 {
164 HashMap<const JSC::HashTable*, JSC::HashTable>::iterator mapEnd = m_map.end();
165 for (HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.begin(); iter != m_map.end(); ++iter)
166 iter->second.deleteTable();
167 }
168
get(const JSC::HashTable * staticTable)169 const JSC::HashTable* get(const JSC::HashTable* staticTable)
170 {
171 HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.find(staticTable);
172 if (iter != m_map.end())
173 return &iter->second;
174 return &m_map.set(staticTable, JSC::HashTable(*staticTable)).first->second;
175 }
176
177 private:
178 HashMap<const JSC::HashTable*, JSC::HashTable> m_map;
179 };
180
181 class WebCoreJSClientData : public JSGlobalData::ClientData {
182 public:
183 DOMObjectHashTableMap hashTableMap;
184 DOMObjectWrapperMap wrapperMap;
185 };
186
mapFor(JSGlobalData & globalData)187 DOMObjectHashTableMap& DOMObjectHashTableMap::mapFor(JSGlobalData& globalData)
188 {
189 JSGlobalData::ClientData* clientData = globalData.clientData;
190 if (!clientData) {
191 clientData = new WebCoreJSClientData;
192 globalData.clientData = clientData;
193 }
194 return static_cast<WebCoreJSClientData*>(clientData)->hashTableMap;
195 }
196
getHashTableForGlobalData(JSGlobalData & globalData,const JSC::HashTable * staticTable)197 const JSC::HashTable* getHashTableForGlobalData(JSGlobalData& globalData, const JSC::HashTable* staticTable)
198 {
199 return DOMObjectHashTableMap::mapFor(globalData).get(staticTable);
200 }
201
mapFor(JSGlobalData & globalData)202 inline DOMObjectWrapperMap& DOMObjectWrapperMap::mapFor(JSGlobalData& globalData)
203 {
204 JSGlobalData::ClientData* clientData = globalData.clientData;
205 if (!clientData) {
206 clientData = new WebCoreJSClientData;
207 globalData.clientData = clientData;
208 }
209 return static_cast<WebCoreJSClientData*>(clientData)->wrapperMap;
210 }
211
getCachedDOMObjectWrapper(JSGlobalData & globalData,void * objectHandle)212 DOMObject* getCachedDOMObjectWrapper(JSGlobalData& globalData, void* objectHandle)
213 {
214 return DOMObjectWrapperMap::mapFor(globalData).get(objectHandle);
215 }
216
cacheDOMObjectWrapper(JSGlobalData & globalData,void * objectHandle,DOMObject * wrapper)217 void cacheDOMObjectWrapper(JSGlobalData& globalData, void* objectHandle, DOMObject* wrapper)
218 {
219 DOMObjectWrapperMap::mapFor(globalData).set(objectHandle, wrapper);
220 }
221
forgetDOMObject(JSGlobalData & globalData,void * objectHandle)222 void forgetDOMObject(JSGlobalData& globalData, void* objectHandle)
223 {
224 DOMObjectWrapperMap::mapFor(globalData).remove(objectHandle);
225 }
226
getCachedDOMNodeWrapper(Document * document,Node * node)227 JSNode* getCachedDOMNodeWrapper(Document* document, Node* node)
228 {
229 if (!document)
230 return static_cast<JSNode*>(DOMObjectWrapperMap::mapFor(*JSDOMWindow::commonJSGlobalData()).get(node));
231 return document->wrapperCache().get(node);
232 }
233
forgetDOMNode(Document * document,Node * node)234 void forgetDOMNode(Document* document, Node* node)
235 {
236 if (!document) {
237 DOMObjectWrapperMap::mapFor(*JSDOMWindow::commonJSGlobalData()).remove(node);
238 return;
239 }
240 removeWrapper(document->wrapperCache().take(node));
241 }
242
cacheDOMNodeWrapper(Document * document,Node * node,JSNode * wrapper)243 void cacheDOMNodeWrapper(Document* document, Node* node, JSNode* wrapper)
244 {
245 if (!document) {
246 DOMObjectWrapperMap::mapFor(*JSDOMWindow::commonJSGlobalData()).set(node, wrapper);
247 return;
248 }
249 addWrapper(wrapper);
250 document->wrapperCache().set(node, wrapper);
251 }
252
forgetAllDOMNodesForDocument(Document * document)253 void forgetAllDOMNodesForDocument(Document* document)
254 {
255 ASSERT(document);
256 removeWrappers(document->wrapperCache());
257 }
258
isObservableThroughDOM(JSNode * jsNode)259 static inline bool isObservableThroughDOM(JSNode* jsNode)
260 {
261 // Certain conditions implicitly make a JS DOM node wrapper observable
262 // through the DOM, even if no explicit reference to it remains.
263
264 Node* node = jsNode->impl();
265
266 if (node->inDocument()) {
267 // 1. If a node is in the document, and its wrapper has custom properties,
268 // the wrapper is observable because future access to the node through the
269 // DOM must reflect those properties.
270 if (jsNode->hasCustomProperties())
271 return true;
272
273 // 2. If a node is in the document, and has event listeners, its wrapper is
274 // observable because its wrapper is responsible for marking those event listeners.
275 if (node->eventListeners().size())
276 return true; // Technically, we may overzealously mark a wrapper for a node that has only non-JS event listeners. Oh well.
277 } else {
278 // 3. If a wrapper is the last reference to an image or script element
279 // that is loading but not in the document, the wrapper is observable
280 // because it is the only thing keeping the image element alive, and if
281 // the image element is destroyed, its load event will not fire.
282 // FIXME: The DOM should manage this issue without the help of JavaScript wrappers.
283 if (node->hasTagName(imgTag) && !static_cast<HTMLImageElement*>(node)->haveFiredLoadEvent())
284 return true;
285 if (node->hasTagName(scriptTag) && !static_cast<HTMLScriptElement*>(node)->haveFiredLoadEvent())
286 return true;
287 #if ENABLE(VIDEO)
288 if (node->hasTagName(audioTag) && !static_cast<HTMLAudioElement*>(node)->paused())
289 return true;
290 #endif
291 }
292
293 return false;
294 }
295
markDOMNodesForDocument(MarkStack & markStack,Document * doc)296 void markDOMNodesForDocument(MarkStack& markStack, Document* doc)
297 {
298 JSWrapperCache& nodeDict = doc->wrapperCache();
299 JSWrapperCache::iterator nodeEnd = nodeDict.end();
300 for (JSWrapperCache::iterator nodeIt = nodeDict.begin(); nodeIt != nodeEnd; ++nodeIt) {
301 JSNode* jsNode = nodeIt->second;
302 if (isObservableThroughDOM(jsNode))
303 markStack.append(jsNode);
304 }
305 }
306
markActiveObjectsForContext(MarkStack & markStack,JSGlobalData & globalData,ScriptExecutionContext * scriptExecutionContext)307 void markActiveObjectsForContext(MarkStack& markStack, JSGlobalData& globalData, ScriptExecutionContext* scriptExecutionContext)
308 {
309 // If an element has pending activity that may result in event listeners being called
310 // (e.g. an XMLHttpRequest), we need to keep JS wrappers alive.
311
312 const HashMap<ActiveDOMObject*, void*>& activeObjects = scriptExecutionContext->activeDOMObjects();
313 HashMap<ActiveDOMObject*, void*>::const_iterator activeObjectsEnd = activeObjects.end();
314 for (HashMap<ActiveDOMObject*, void*>::const_iterator iter = activeObjects.begin(); iter != activeObjectsEnd; ++iter) {
315 if (iter->first->hasPendingActivity()) {
316 DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, iter->second);
317 // Generally, an active object with pending activity must have a wrapper to mark its listeners.
318 // However, some ActiveDOMObjects don't have JS wrappers (timers created by setTimeout is one example).
319 // FIXME: perhaps need to make sure even timers have a markable 'wrapper'.
320 if (wrapper)
321 markStack.append(wrapper);
322 }
323 }
324
325 const HashSet<MessagePort*>& messagePorts = scriptExecutionContext->messagePorts();
326 HashSet<MessagePort*>::const_iterator portsEnd = messagePorts.end();
327 for (HashSet<MessagePort*>::const_iterator iter = messagePorts.begin(); iter != portsEnd; ++iter) {
328 // If the message port is remotely entangled, then always mark it as in-use because we can't determine reachability across threads.
329 if (!(*iter)->locallyEntangledPort() || (*iter)->hasPendingActivity()) {
330 DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, *iter);
331 if (wrapper)
332 markStack.append(wrapper);
333 }
334 }
335 }
336
updateDOMNodeDocument(Node * node,Document * oldDocument,Document * newDocument)337 void updateDOMNodeDocument(Node* node, Document* oldDocument, Document* newDocument)
338 {
339 ASSERT(oldDocument != newDocument);
340 JSNode* wrapper = getCachedDOMNodeWrapper(oldDocument, node);
341 if (!wrapper)
342 return;
343 removeWrapper(wrapper);
344 cacheDOMNodeWrapper(newDocument, node, wrapper);
345 forgetDOMNode(oldDocument, node);
346 addWrapper(wrapper);
347 }
348
markDOMObjectWrapper(MarkStack & markStack,JSGlobalData & globalData,void * object)349 void markDOMObjectWrapper(MarkStack& markStack, JSGlobalData& globalData, void* object)
350 {
351 if (!object)
352 return;
353 DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, object);
354 if (!wrapper)
355 return;
356 markStack.append(wrapper);
357 }
358
jsStringOrNull(ExecState * exec,const String & s)359 JSValue jsStringOrNull(ExecState* exec, const String& s)
360 {
361 if (s.isNull())
362 return jsNull();
363 return jsString(exec, s);
364 }
365
jsOwnedStringOrNull(ExecState * exec,const UString & s)366 JSValue jsOwnedStringOrNull(ExecState* exec, const UString& s)
367 {
368 if (s.isNull())
369 return jsNull();
370 return jsOwnedString(exec, s);
371 }
372
jsStringOrUndefined(ExecState * exec,const String & s)373 JSValue jsStringOrUndefined(ExecState* exec, const String& s)
374 {
375 if (s.isNull())
376 return jsUndefined();
377 return jsString(exec, s);
378 }
379
jsStringOrFalse(ExecState * exec,const String & s)380 JSValue jsStringOrFalse(ExecState* exec, const String& s)
381 {
382 if (s.isNull())
383 return jsBoolean(false);
384 return jsString(exec, s);
385 }
386
jsStringOrNull(ExecState * exec,const KURL & url)387 JSValue jsStringOrNull(ExecState* exec, const KURL& url)
388 {
389 if (url.isNull())
390 return jsNull();
391 return jsString(exec, url.string());
392 }
393
jsStringOrUndefined(ExecState * exec,const KURL & url)394 JSValue jsStringOrUndefined(ExecState* exec, const KURL& url)
395 {
396 if (url.isNull())
397 return jsUndefined();
398 return jsString(exec, url.string());
399 }
400
jsStringOrFalse(ExecState * exec,const KURL & url)401 JSValue jsStringOrFalse(ExecState* exec, const KURL& url)
402 {
403 if (url.isNull())
404 return jsBoolean(false);
405 return jsString(exec, url.string());
406 }
407
valueToStringWithNullCheck(ExecState * exec,JSValue value)408 UString valueToStringWithNullCheck(ExecState* exec, JSValue value)
409 {
410 if (value.isNull())
411 return UString();
412 return value.toString(exec);
413 }
414
valueToStringWithUndefinedOrNullCheck(ExecState * exec,JSValue value)415 UString valueToStringWithUndefinedOrNullCheck(ExecState* exec, JSValue value)
416 {
417 if (value.isUndefinedOrNull())
418 return UString();
419 return value.toString(exec);
420 }
421
reportException(ExecState * exec,JSValue exception)422 void reportException(ExecState* exec, JSValue exception)
423 {
424 UString errorMessage = exception.toString(exec);
425 JSObject* exceptionObject = exception.toObject(exec);
426 int lineNumber = exceptionObject->get(exec, Identifier(exec, "line")).toInt32(exec);
427 UString exceptionSourceURL = exceptionObject->get(exec, Identifier(exec, "sourceURL")).toString(exec);
428 exec->clearException();
429
430 ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext();
431 ASSERT(scriptExecutionContext);
432
433 // Crash data indicates null-dereference crashes at this point in the Safari 4 Public Beta.
434 // It's harmless to return here without reporting the exception to the log and the debugger in this case.
435 if (!scriptExecutionContext)
436 return;
437
438 scriptExecutionContext->reportException(errorMessage, lineNumber, exceptionSourceURL);
439 }
440
reportCurrentException(ExecState * exec)441 void reportCurrentException(ExecState* exec)
442 {
443 JSValue exception = exec->exception();
444 exec->clearException();
445 reportException(exec, exception);
446 }
447
setDOMException(ExecState * exec,ExceptionCode ec)448 void setDOMException(ExecState* exec, ExceptionCode ec)
449 {
450 if (!ec || exec->hadException())
451 return;
452
453 // FIXME: All callers to setDOMException need to pass in the right global object
454 // for now, we're going to assume the lexicalGlobalObject. Which is wrong in cases like this:
455 // frames[0].document.createElement(null, null); // throws an exception which should have the subframes prototypes.
456 JSDOMGlobalObject* globalObject = deprecatedGlobalObjectForPrototype(exec);
457
458 ExceptionCodeDescription description;
459 getExceptionCodeDescription(ec, description);
460
461 JSValue errorObject;
462 switch (description.type) {
463 case DOMExceptionType:
464 errorObject = toJS(exec, globalObject, DOMCoreException::create(description));
465 break;
466 case RangeExceptionType:
467 errorObject = toJS(exec, globalObject, RangeException::create(description));
468 break;
469 case EventExceptionType:
470 errorObject = toJS(exec, globalObject, EventException::create(description));
471 break;
472 case XMLHttpRequestExceptionType:
473 errorObject = toJS(exec, globalObject, XMLHttpRequestException::create(description));
474 break;
475 #if ENABLE(SVG)
476 case SVGExceptionType:
477 errorObject = toJS(exec, globalObject, SVGException::create(description).get(), 0);
478 break;
479 #endif
480 #if ENABLE(XPATH)
481 case XPathExceptionType:
482 errorObject = toJS(exec, globalObject, XPathException::create(description));
483 break;
484 #endif
485 }
486
487 ASSERT(errorObject);
488 exec->setException(errorObject);
489 }
490
checkNodeSecurity(ExecState * exec,Node * node)491 bool checkNodeSecurity(ExecState* exec, Node* node)
492 {
493 return node && allowsAccessFromFrame(exec, node->document()->frame());
494 }
495
allowsAccessFromFrame(ExecState * exec,Frame * frame)496 bool allowsAccessFromFrame(ExecState* exec, Frame* frame)
497 {
498 if (!frame)
499 return false;
500 JSDOMWindow* window = toJSDOMWindow(frame);
501 return window && window->allowsAccessFrom(exec);
502 }
503
allowsAccessFromFrame(ExecState * exec,Frame * frame,String & message)504 bool allowsAccessFromFrame(ExecState* exec, Frame* frame, String& message)
505 {
506 if (!frame)
507 return false;
508 JSDOMWindow* window = toJSDOMWindow(frame);
509 return window && window->allowsAccessFrom(exec, message);
510 }
511
shouldAllowNavigation(ExecState * exec,Frame * frame)512 bool shouldAllowNavigation(ExecState* exec, Frame* frame)
513 {
514 Frame* lexicalFrame = toLexicalFrame(exec);
515 return lexicalFrame && lexicalFrame->loader()->shouldAllowNavigation(frame);
516 }
517
printErrorMessageForFrame(Frame * frame,const String & message)518 void printErrorMessageForFrame(Frame* frame, const String& message)
519 {
520 if (!frame)
521 return;
522 if (JSDOMWindow* window = toJSDOMWindow(frame))
523 window->printErrorMessage(message);
524 }
525
toLexicalFrame(ExecState * exec)526 Frame* toLexicalFrame(ExecState* exec)
527 {
528 return asJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame();
529 }
530
toDynamicFrame(ExecState * exec)531 Frame* toDynamicFrame(ExecState* exec)
532 {
533 return asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
534 }
535
processingUserGesture(ExecState * exec)536 bool processingUserGesture(ExecState* exec)
537 {
538 Frame* frame = toDynamicFrame(exec);
539 return frame && frame->script()->processingUserGesture();
540 }
541
completeURL(ExecState * exec,const String & relativeURL)542 KURL completeURL(ExecState* exec, const String& relativeURL)
543 {
544 // For histoical reasons, we need to complete the URL using the dynamic frame.
545 Frame* frame = toDynamicFrame(exec);
546 if (!frame)
547 return KURL();
548 return frame->loader()->completeURL(relativeURL);
549 }
550
objectToStringFunctionGetter(ExecState * exec,const Identifier & propertyName,const PropertySlot &)551 JSValue objectToStringFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&)
552 {
553 return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject()->prototypeFunctionStructure(), 0, propertyName, objectProtoFuncToString);
554 }
555
getCachedDOMStructure(JSDOMGlobalObject * globalObject,const ClassInfo * classInfo)556 Structure* getCachedDOMStructure(JSDOMGlobalObject* globalObject, const ClassInfo* classInfo)
557 {
558 JSDOMStructureMap& structures = globalObject->structures();
559 return structures.get(classInfo).get();
560 }
561
cacheDOMStructure(JSDOMGlobalObject * globalObject,PassRefPtr<Structure> structure,const ClassInfo * classInfo)562 Structure* cacheDOMStructure(JSDOMGlobalObject* globalObject, PassRefPtr<Structure> structure, const ClassInfo* classInfo)
563 {
564 JSDOMStructureMap& structures = globalObject->structures();
565 ASSERT(!structures.contains(classInfo));
566 return structures.set(classInfo, structure).first->second.get();
567 }
568
getCachedDOMStructure(ExecState * exec,const ClassInfo * classInfo)569 Structure* getCachedDOMStructure(ExecState* exec, const ClassInfo* classInfo)
570 {
571 return getCachedDOMStructure(static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), classInfo);
572 }
573
cacheDOMStructure(ExecState * exec,PassRefPtr<Structure> structure,const ClassInfo * classInfo)574 Structure* cacheDOMStructure(ExecState* exec, PassRefPtr<Structure> structure, const ClassInfo* classInfo)
575 {
576 return cacheDOMStructure(static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), structure, classInfo);
577 }
578
getCachedDOMConstructor(ExecState * exec,const ClassInfo * classInfo)579 JSObject* getCachedDOMConstructor(ExecState* exec, const ClassInfo* classInfo)
580 {
581 JSDOMConstructorMap& constructors = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->constructors();
582 return constructors.get(classInfo);
583 }
584
cacheDOMConstructor(ExecState * exec,const ClassInfo * classInfo,JSObject * constructor)585 void cacheDOMConstructor(ExecState* exec, const ClassInfo* classInfo, JSObject* constructor)
586 {
587 JSDOMConstructorMap& constructors = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->constructors();
588 ASSERT(!constructors.contains(classInfo));
589 constructors.set(classInfo, constructor);
590 }
591
592 } // namespace WebCore
593