| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return UserGestureIndicator::processingUserGesture(); | 171 return UserGestureIndicator::processingUserGesture(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[]) | 174 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[]) |
| 175 { | 175 { |
| 176 // Keep Frame (and therefore ScriptController) alive. | 176 // Keep Frame (and therefore ScriptController) alive. |
| 177 RefPtr<Frame> protect(m_frame); | 177 RefPtr<Frame> protect(m_frame); |
| 178 return ScriptController::callFunctionWithInstrumentation(m_frame ? m_frame->
document() : 0, function, receiver, argc, args); | 178 return ScriptController::callFunctionWithInstrumentation(m_frame ? m_frame->
document() : 0, function, receiver, argc, args); |
| 179 } | 179 } |
| 180 | 180 |
| 181 static inline void resourceInfo(const v8::Handle<v8::Function> function, String&
resourceName, int& lineNumber) | 181 static void resourceInfo(const v8::Handle<v8::Function> function, String& resour
ceName, int& lineNumber) |
| 182 { | 182 { |
| 183 v8::ScriptOrigin origin = function->GetScriptOrigin(); | 183 v8::ScriptOrigin origin = function->GetScriptOrigin(); |
| 184 if (origin.ResourceName().IsEmpty()) { | 184 if (origin.ResourceName().IsEmpty()) { |
| 185 resourceName = "undefined"; | 185 resourceName = "undefined"; |
| 186 lineNumber = 1; | 186 lineNumber = 1; |
| 187 } else { | 187 } else { |
| 188 resourceName = toWebCoreString(origin.ResourceName()); | 188 resourceName = toWebCoreString(origin.ResourceName()); |
| 189 lineNumber = function->GetScriptLineNumber() + 1; | 189 lineNumber = function->GetScriptLineNumber() + 1; |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 static inline String resourceString(const v8::Handle<v8::Function> function) | 193 static String resourceString(const v8::Handle<v8::Function> function) |
| 194 { | 194 { |
| 195 String resourceName; | 195 String resourceName; |
| 196 int lineNumber; | 196 int lineNumber; |
| 197 resourceInfo(function, resourceName, lineNumber); | 197 resourceInfo(function, resourceName, lineNumber); |
| 198 | 198 |
| 199 StringBuilder builder; | 199 StringBuilder builder; |
| 200 builder.append(resourceName); | 200 builder.append(resourceName); |
| 201 builder.append(':'); | 201 builder.append(':'); |
| 202 builder.appendNumber(lineNumber); | 202 builder.appendNumber(lineNumber); |
| 203 return builder.toString(); | 203 return builder.toString(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 v8::Local<v8::Value> ScriptController::callFunctionWithInstrumentation(ScriptExe
cutionContext* context, v8::Handle<v8::Function> function, v8::Handle<v8::Object
> receiver, int argc, v8::Handle<v8::Value> args[]) | 206 v8::Local<v8::Value> ScriptController::callFunctionWithInstrumentation(ScriptExe
cutionContext* context, v8::Handle<v8::Function> function, v8::Handle<v8::Object
> receiver, int argc, v8::Handle<v8::Value> args[]) |
| 207 { | 207 { |
| 208 V8GCController::checkMemoryUsage(); | |
| 209 | |
| 210 if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth) | |
| 211 return handleMaxRecursionDepthExceeded(); | |
| 212 | |
| 213 InspectorInstrumentationCookie cookie; | 208 InspectorInstrumentationCookie cookie; |
| 214 if (InspectorInstrumentation::timelineAgentEnabled(context)) { | 209 if (InspectorInstrumentation::timelineAgentEnabled(context)) { |
| 215 String resourceName; | 210 String resourceName; |
| 216 int lineNumber; | 211 int lineNumber; |
| 217 resourceInfo(function, resourceName, lineNumber); | 212 resourceInfo(function, resourceName, lineNumber); |
| 218 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); | 213 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); |
| 219 } | 214 } |
| 220 | 215 |
| 221 v8::Local<v8::Value> result; | 216 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context
, receiver, argc, args); |
| 222 { | |
| 223 TRACE_EVENT1("v8", "v8.callFunction", "callsite", resourceString(functio
n).utf8()); | |
| 224 V8RecursionScope recursionScope(context); | |
| 225 result = function->Call(receiver, argc, args); | |
| 226 } | |
| 227 | 217 |
| 228 InspectorInstrumentation::didCallFunction(cookie); | 218 InspectorInstrumentation::didCallFunction(cookie); |
| 229 crashIfV8IsDead(); | |
| 230 return result; | 219 return result; |
| 231 } | 220 } |
| 232 | 221 |
| 233 ScriptValue ScriptController::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Fu
nction> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Valu
e> argv[]) | 222 ScriptValue ScriptController::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Fu
nction> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Valu
e> argv[]) |
| 234 { | 223 { |
| 235 // FIXME: This should probably perform the same isPaused check that happens
in ScriptController::executeScript. | 224 // FIXME: This should probably perform the same isPaused check that happens
in ScriptController::executeScript. |
| 236 return ScriptValue(callFunction(function, receiver, argc, argv)); | 225 return ScriptValue(callFunction(function, receiver, argc, argv)); |
| 237 } | 226 } |
| 238 | 227 |
| 239 v8::Local<v8::Value> ScriptController::compileAndRunScript(const ScriptSourceCod
e& source) | 228 v8::Local<v8::Value> ScriptController::compileAndRunScript(const ScriptSourceCod
e& source) |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 v8::Context::Scope scope(v8Context); | 582 v8::Context::Scope scope(v8Context); |
| 594 | 583 |
| 595 DOMWindow* window = m_frame->document()->domWindow(); | 584 DOMWindow* window = m_frame->document()->domWindow(); |
| 596 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); | 585 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); |
| 597 if (!v8plugin->IsObject()) | 586 if (!v8plugin->IsObject()) |
| 598 return createNoScriptObject(); | 587 return createNoScriptObject(); |
| 599 | 588 |
| 600 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), win
dow); | 589 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), win
dow); |
| 601 } | 590 } |
| 602 | 591 |
| 603 | |
| 604 void ScriptController::clearWindowShell() | 592 void ScriptController::clearWindowShell() |
| 605 { | 593 { |
| 606 double start = currentTime(); | 594 double start = currentTime(); |
| 607 // V8 binding expects ScriptController::clearWindowShell only be called | 595 // V8 binding expects ScriptController::clearWindowShell only be called |
| 608 // when a frame is loading a new page. This creates a new context for the ne
w page. | 596 // when a frame is loading a new page. This creates a new context for the ne
w page. |
| 609 m_windowShell->clearForNavigation(); | 597 m_windowShell->clearForNavigation(); |
| 610 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 598 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) |
| 611 iter->value->clearForNavigation(); | 599 iter->value->clearForNavigation(); |
| 612 V8GCController::hintForCollectGarbage(); | 600 V8GCController::hintForCollectGarbage(); |
| 613 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); | 601 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 ASSERT(m_frame->document()->loader()); | 726 ASSERT(m_frame->document()->loader()); |
| 739 | 727 |
| 740 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref
'ed and possible destroyed, | 728 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref
'ed and possible destroyed, |
| 741 // so protect it with a RefPtr. | 729 // so protect it with a RefPtr. |
| 742 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) | 730 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) |
| 743 loader->writer()->replaceDocument(scriptResult, ownerDocument.get()); | 731 loader->writer()->replaceDocument(scriptResult, ownerDocument.get()); |
| 744 return true; | 732 return true; |
| 745 } | 733 } |
| 746 | 734 |
| 747 } // namespace WebCore | 735 } // namespace WebCore |
| OLD | NEW |