2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
4 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
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.
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.
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
25 #include "CollectorHeapIterator.h"
27 #include "Interpreter.h"
28 #include "JSFunction.h"
29 #include "JSGlobalObject.h"
37 HashSet
<JSGlobalObject
*>::iterator end
= m_globalObjects
.end();
38 for (HashSet
<JSGlobalObject
*>::iterator it
= m_globalObjects
.begin(); it
!= end
; ++it
)
39 (*it
)->setDebugger(0);
42 void Debugger::attach(JSGlobalObject
* globalObject
)
44 ASSERT(!globalObject
->debugger());
45 globalObject
->setDebugger(this);
46 m_globalObjects
.add(globalObject
);
49 void Debugger::detach(JSGlobalObject
* globalObject
)
51 ASSERT(m_globalObjects
.contains(globalObject
));
52 m_globalObjects
.remove(globalObject
);
53 globalObject
->setDebugger(0);
56 void Debugger::recompileAllJSFunctions(JSGlobalData
* globalData
)
58 // If JavaScript is running, it's not safe to recompile, since we'll end
59 // up throwing away code that is live on the stack.
60 ASSERT(!globalData
->dynamicGlobalObject
);
61 if (globalData
->dynamicGlobalObject
)
64 typedef HashSet
<FunctionExecutable
*> FunctionExecutableSet
;
65 typedef HashMap
<SourceProvider
*, ExecState
*> SourceProviderMap
;
67 FunctionExecutableSet functionExecutables
;
68 SourceProviderMap sourceProviders
;
70 LiveObjectIterator it
= globalData
->heap
.primaryHeapBegin();
71 LiveObjectIterator heapEnd
= globalData
->heap
.primaryHeapEnd();
72 for ( ; it
!= heapEnd
; ++it
) {
73 if (!(*it
)->inherits(&JSFunction::info
))
76 JSFunction
* function
= asFunction(*it
);
77 if (function
->executable()->isHostFunction())
80 FunctionExecutable
* executable
= function
->jsExecutable();
82 // Check if the function is already in the set - if so,
83 // we've already retranslated it, nothing to do here.
84 if (!functionExecutables
.add(executable
).second
)
87 ExecState
* exec
= function
->scope().globalObject()->JSGlobalObject::globalExec();
88 executable
->recompile(exec
);
89 if (function
->scope().globalObject()->debugger() == this)
90 sourceProviders
.add(executable
->source().provider(), exec
);
93 // Call sourceParsed() after reparsing all functions because it will execute
94 // JavaScript in the inspector.
95 SourceProviderMap::const_iterator end
= sourceProviders
.end();
96 for (SourceProviderMap::const_iterator iter
= sourceProviders
.begin(); iter
!= end
; ++iter
)
97 sourceParsed(iter
->second
, SourceCode(iter
->first
), -1, 0);
100 JSValue
evaluateInGlobalCallFrame(const UString
& script
, JSValue
& exception
, JSGlobalObject
* globalObject
)
102 CallFrame
* globalCallFrame
= globalObject
->globalExec();
104 RefPtr
<EvalExecutable
> eval
= EvalExecutable::create(globalCallFrame
, makeSource(script
));
105 JSObject
* error
= eval
->compile(globalCallFrame
, globalCallFrame
->scopeChain());
109 return globalObject
->globalData()->interpreter
->execute(eval
.get(), globalCallFrame
, globalObject
, globalCallFrame
->scopeChain(), &exception
);