source: webkit/trunk/JavaScriptCore/debugger/Debugger.cpp@ 57925

Last change on this file since 57925 was 54464, checked in by [email protected], 15 years ago

Change UStringImpl::create to CRASH if the string cannot be allocated,
rather than returning a null string (which will behave like a zero-length
string if used).

Reviewed by Geoff Garen.

Also move createRep function from UString to become new overloaded
UStringImpl::create methods. In doing so, bring their behaviour closer to
being in line with WebCore::StringImpl, in removing the behaviour that they
can be used to produce null UStrings (ASSERT the char* provided is non-null).
This behaviour of converting null C-strings to null UStrings is inefficient
(cmompared to just using UString::null()), incompatible with WebCore::StringImpl's
behaviour, and may generate unexpected behaviour, since in many cases a null
UString can be used like an empty string.

With these changes UStringImpl need not have a concept of null impls, we can
start transitioning this to become an implementation detail of UString, that
internally it chooses to use a null-object rather than an actually zero impl
pointer.

(JSC::Debugger::recompileAllJSFunctions):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::calculatedFunctionName):

  • parser/Parser.cpp:

(JSC::Parser::parse):

  • profiler/Profile.cpp:

(JSC::Profile::Profile):

  • profiler/ProfileGenerator.cpp:

(JSC::ProfileGenerator::stopProfiling):

  • runtime/Error.cpp:

(JSC::Error::create):
(JSC::throwError):

  • runtime/ExceptionHelpers.cpp:

(JSC::createError):

  • runtime/Identifier.cpp:

(JSC::Identifier::add):

  • runtime/PropertyNameArray.cpp:

(JSC::PropertyNameArray::add):

  • runtime/UString.cpp:

(JSC::initializeUString):
(JSC::UString::UString):
(JSC::UString::operator=):

  • runtime/UString.h:

(JSC::UString::isNull):
(JSC::UString::null):
(JSC::UString::rep):
(JSC::UString::UString):

  • runtime/UStringImpl.cpp:

(JSC::UStringImpl::create):

  • runtime/UStringImpl.h:
  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 1999-2001 Harri Porten ([email protected])
4 * Copyright (C) 2001 Peter Kelly ([email protected])
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
22#include "config.h"
23#include "Debugger.h"
24
25#include "CollectorHeapIterator.h"
26#include "Error.h"
27#include "Interpreter.h"
28#include "JSFunction.h"
29#include "JSGlobalObject.h"
30#include "Parser.h"
31#include "Protect.h"
32
33namespace JSC {
34
35Debugger::~Debugger()
36{
37 HashSet<JSGlobalObject*>::iterator end = m_globalObjects.end();
38 for (HashSet<JSGlobalObject*>::iterator it = m_globalObjects.begin(); it != end; ++it)
39 (*it)->setDebugger(0);
40}
41
42void Debugger::attach(JSGlobalObject* globalObject)
43{
44 ASSERT(!globalObject->debugger());
45 globalObject->setDebugger(this);
46 m_globalObjects.add(globalObject);
47}
48
49void Debugger::detach(JSGlobalObject* globalObject)
50{
51 ASSERT(m_globalObjects.contains(globalObject));
52 m_globalObjects.remove(globalObject);
53 globalObject->setDebugger(0);
54}
55
56void Debugger::recompileAllJSFunctions(JSGlobalData* globalData)
57{
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)
62 return;
63
64 typedef HashSet<FunctionExecutable*> FunctionExecutableSet;
65 typedef HashMap<SourceProvider*, ExecState*> SourceProviderMap;
66
67 FunctionExecutableSet functionExecutables;
68 SourceProviderMap sourceProviders;
69
70 LiveObjectIterator it = globalData->heap.primaryHeapBegin();
71 LiveObjectIterator heapEnd = globalData->heap.primaryHeapEnd();
72 for ( ; it != heapEnd; ++it) {
73 if (!(*it)->inherits(&JSFunction::info))
74 continue;
75
76 JSFunction* function = asFunction(*it);
77 if (function->executable()->isHostFunction())
78 continue;
79
80 FunctionExecutable* executable = function->jsExecutable();
81
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)
85 continue;
86
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);
91 }
92
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, UString());
98}
99
100JSValue evaluateInGlobalCallFrame(const UString& script, JSValue& exception, JSGlobalObject* globalObject)
101{
102 CallFrame* globalCallFrame = globalObject->globalExec();
103
104 RefPtr<EvalExecutable> eval = EvalExecutable::create(globalCallFrame, makeSource(script));
105 JSObject* error = eval->compile(globalCallFrame, globalCallFrame->scopeChain());
106 if (error)
107 return error;
108
109 return globalObject->globalData()->interpreter->execute(eval.get(), globalCallFrame, globalObject, globalCallFrame->scopeChain(), &exception);
110}
111
112} // namespace JSC
Note: See TracBrowser for help on using the repository browser.