| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 ScriptValue ScriptController::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Fu
nction> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Valu
e> argv[]) | 181 ScriptValue ScriptController::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Fu
nction> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Valu
e> argv[]) |
| 182 { | 182 { |
| 183 // FIXME: This should probably perform the same isPaused check that happens
in ScriptController::executeScript. | 183 // FIXME: This should probably perform the same isPaused check that happens
in ScriptController::executeScript. |
| 184 return ScriptValue(callFunction(function, receiver, argc, argv)); | 184 return ScriptValue(callFunction(function, receiver, argc, argv)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 static inline void resourceInfo(const v8::Handle<v8::Function> function, String&
resourceName, int& lineNumber) | 187 static void resourceInfo(const v8::Handle<v8::Function> function, String& resour
ceName, int& lineNumber) |
| 188 { | 188 { |
| 189 v8::ScriptOrigin origin = function->GetScriptOrigin(); | 189 v8::ScriptOrigin origin = function->GetScriptOrigin(); |
| 190 if (origin.ResourceName().IsEmpty()) { | 190 if (origin.ResourceName().IsEmpty()) { |
| 191 resourceName = "undefined"; | 191 resourceName = "undefined"; |
| 192 lineNumber = 1; | 192 lineNumber = 1; |
| 193 } else { | 193 } else { |
| 194 resourceName = toWebCoreString(origin.ResourceName()); | 194 resourceName = toWebCoreString(origin.ResourceName()); |
| 195 lineNumber = function->GetScriptLineNumber() + 1; | 195 lineNumber = function->GetScriptLineNumber() + 1; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 static inline String resourceString(const v8::Handle<v8::Function> function) | 199 static String resourceString(const v8::Handle<v8::Function> function) |
| 200 { | 200 { |
| 201 String resourceName; | 201 String resourceName; |
| 202 int lineNumber; | 202 int lineNumber; |
| 203 resourceInfo(function, resourceName, lineNumber); | 203 resourceInfo(function, resourceName, lineNumber); |
| 204 | 204 |
| 205 StringBuilder builder; | 205 StringBuilder builder; |
| 206 builder.append(resourceName); | 206 builder.append(resourceName); |
| 207 builder.append(':'); | 207 builder.append(':'); |
| 208 builder.appendNumber(lineNumber); | 208 builder.appendNumber(lineNumber); |
| 209 return builder.toString(); | 209 return builder.toString(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 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[]) | 212 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[]) |
| 213 { | 213 { |
| 214 V8GCController::checkMemoryUsage(); | |
| 215 | |
| 216 if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth) | |
| 217 return handleMaxRecursionDepthExceeded(); | |
| 218 | |
| 219 InspectorInstrumentationCookie cookie; | 214 InspectorInstrumentationCookie cookie; |
| 220 if (InspectorInstrumentation::timelineAgentEnabled(context)) { | 215 if (InspectorInstrumentation::timelineAgentEnabled(context)) { |
| 221 String resourceName; | 216 String resourceName; |
| 222 int lineNumber; | 217 int lineNumber; |
| 223 resourceInfo(function, resourceName, lineNumber); | 218 resourceInfo(function, resourceName, lineNumber); |
| 224 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); | 219 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); |
| 225 } | 220 } |
| 226 | 221 |
| 227 v8::Local<v8::Value> result; | 222 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context
, receiver, argc, args); |
| 228 { | |
| 229 TRACE_EVENT1("v8", "v8.callFunction", "callsite", resourceString(functio
n).utf8()); | |
| 230 V8RecursionScope recursionScope(context); | |
| 231 result = function->Call(receiver, argc, args); | |
| 232 } | |
| 233 | 223 |
| 234 InspectorInstrumentation::didCallFunction(cookie); | 224 InspectorInstrumentation::didCallFunction(cookie); |
| 235 crashIfV8IsDead(); | |
| 236 return result; | 225 return result; |
| 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) |
| 240 { | 229 { |
| 241 ASSERT(v8::Context::InContext()); | 230 ASSERT(v8::Context::InContext()); |
| 242 | 231 |
| 243 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua
teScript(m_frame, source.url().isNull() ? String() : source.url().string(), sour
ce.startLine()); | 232 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua
teScript(m_frame, source.url().isNull() ? String() : source.url().string(), sour
ce.startLine()); |
| 244 | 233 |
| 245 v8::Local<v8::Value> result; | 234 v8::Local<v8::Value> result; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 v8::Context::Scope scope(v8Context); | 523 v8::Context::Scope scope(v8Context); |
| 535 | 524 |
| 536 DOMWindow* window = m_frame->document()->domWindow(); | 525 DOMWindow* window = m_frame->document()->domWindow(); |
| 537 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); | 526 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); |
| 538 if (!v8plugin->IsObject()) | 527 if (!v8plugin->IsObject()) |
| 539 return createNoScriptObject(); | 528 return createNoScriptObject(); |
| 540 | 529 |
| 541 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), win
dow); | 530 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), win
dow); |
| 542 } | 531 } |
| 543 | 532 |
| 544 | |
| 545 void ScriptController::clearWindowShell() | 533 void ScriptController::clearWindowShell() |
| 546 { | 534 { |
| 547 double start = currentTime(); | 535 double start = currentTime(); |
| 548 // V8 binding expects ScriptController::clearWindowShell only be called | 536 // V8 binding expects ScriptController::clearWindowShell only be called |
| 549 // when a frame is loading a new page. This creates a new context for the ne
w page. | 537 // when a frame is loading a new page. This creates a new context for the ne
w page. |
| 550 m_windowShell->clearForNavigation(); | 538 m_windowShell->clearForNavigation(); |
| 551 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 539 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) |
| 552 iter->value->clearForNavigation(); | 540 iter->value->clearForNavigation(); |
| 553 V8GCController::hintForCollectGarbage(); | 541 V8GCController::hintForCollectGarbage(); |
| 554 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); | 542 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 v8Results = evaluateHandleScope.Close(resultArray); | 724 v8Results = evaluateHandleScope.Close(resultArray); |
| 737 } | 725 } |
| 738 | 726 |
| 739 if (results && !v8Results.IsEmpty()) { | 727 if (results && !v8Results.IsEmpty()) { |
| 740 for (size_t i = 0; i < v8Results->Length(); ++i) | 728 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 741 results->append(ScriptValue(v8Results->Get(i))); | 729 results->append(ScriptValue(v8Results->Get(i))); |
| 742 } | 730 } |
| 743 } | 731 } |
| 744 | 732 |
| 745 } // namespace WebCore | 733 } // namespace WebCore |
| OLD | NEW |