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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 resourceInfo(function, resourceName, lineNumber); | 199 resourceInfo(function, resourceName, lineNumber); |
200 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); | 200 cookie = InspectorInstrumentation::willCallFunction(context, resourceNam
e, lineNumber); |
201 } | 201 } |
202 | 202 |
203 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context
, receiver, argc, args); | 203 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context
, receiver, argc, args); |
204 | 204 |
205 InspectorInstrumentation::didCallFunction(cookie); | 205 InspectorInstrumentation::didCallFunction(cookie); |
206 return result; | 206 return result; |
207 } | 207 } |
208 | 208 |
209 v8::Local<v8::Value> ScriptController::compileAndRunScript(const ScriptSourceCod
e& source) | 209 v8::Local<v8::Value> ScriptController::compileAndRunScript(const ScriptSourceCod
e& source, AccessControlStatus corsStatus) |
210 { | 210 { |
211 ASSERT(v8::Context::InContext()); | 211 ASSERT(v8::Context::InContext()); |
212 | 212 |
213 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua
teScript(m_frame, source.url().isNull() ? String() : source.url().string(), sour
ce.startLine()); | 213 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua
teScript(m_frame, source.url().isNull() ? String() : source.url().string(), sour
ce.startLine()); |
214 | 214 |
215 v8::Local<v8::Value> result; | 215 v8::Local<v8::Value> result; |
216 { | 216 { |
217 // Isolate exceptions that occur when compiling and executing | 217 // Isolate exceptions that occur when compiling and executing |
218 // the code. These exceptions should not interfere with | 218 // the code. These exceptions should not interfere with |
219 // javascript code we might evaluate from C++ when returning | 219 // javascript code we might evaluate from C++ when returning |
220 // from here. | 220 // from here. |
221 v8::TryCatch tryCatch; | 221 v8::TryCatch tryCatch; |
222 tryCatch.SetVerbose(true); | 222 tryCatch.SetVerbose(true); |
223 | 223 |
224 v8::Handle<v8::String> code = v8String(source.source(), m_isolate); | 224 v8::Handle<v8::String> code = v8String(source.source(), m_isolate); |
225 OwnPtr<v8::ScriptData> scriptData = V8ScriptRunner::precompileScript(cod
e, source.cachedScript()); | 225 OwnPtr<v8::ScriptData> scriptData = V8ScriptRunner::precompileScript(cod
e, source.cachedScript()); |
226 | 226 |
227 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts
at | 227 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts
at |
228 // 1, whereas v8 starts at 0. | 228 // 1, whereas v8 starts at 0. |
229 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(code, sour
ce.url(), source.startPosition(), scriptData.get(), m_isolate); | 229 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(code, sour
ce.url(), source.startPosition(), scriptData.get(), m_isolate, corsStatus); |
230 | 230 |
231 // Keep Frame (and therefore ScriptController) alive. | 231 // Keep Frame (and therefore ScriptController) alive. |
232 RefPtr<Frame> protect(m_frame); | 232 RefPtr<Frame> protect(m_frame); |
233 result = V8ScriptRunner::runCompiledScript(script, m_frame->document()); | 233 result = V8ScriptRunner::runCompiledScript(script, m_frame->document()); |
234 ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); | 234 ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); |
235 } | 235 } |
236 | 236 |
237 InspectorInstrumentation::didEvaluateScript(cookie); | 237 InspectorInstrumentation::didEvaluateScript(cookie); |
238 | 238 |
239 return result; | 239 return result; |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangeP
ending()) | 650 if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangeP
ending()) |
651 return true; | 651 return true; |
652 | 652 |
653 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref
'ed and possible destroyed, | 653 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref
'ed and possible destroyed, |
654 // so protect it with a RefPtr. | 654 // so protect it with a RefPtr. |
655 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) | 655 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) |
656 loader->replaceDocument(scriptResult, ownerDocument.get()); | 656 loader->replaceDocument(scriptResult, ownerDocument.get()); |
657 return true; | 657 return true; |
658 } | 658 } |
659 | 659 |
660 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s
ourceCode) | 660 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s
ourceCode, AccessControlStatus corsStatus) |
661 { | 661 { |
662 String sourceURL = sourceCode.url(); | 662 String sourceURL = sourceCode.url(); |
663 const String* savedSourceURL = m_sourceURL; | 663 const String* savedSourceURL = m_sourceURL; |
664 m_sourceURL = &sourceURL; | 664 m_sourceURL = &sourceURL; |
665 | 665 |
666 v8::HandleScope handleScope; | 666 v8::HandleScope handleScope; |
667 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); | 667 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); |
668 if (v8Context.IsEmpty()) | 668 if (v8Context.IsEmpty()) |
669 return ScriptValue(); | 669 return ScriptValue(); |
670 | 670 |
671 v8::Context::Scope scope(v8Context); | 671 v8::Context::Scope scope(v8Context); |
672 RefPtr<Frame> protect(m_frame); | 672 RefPtr<Frame> protect(m_frame); |
673 v8::Local<v8::Value> object = compileAndRunScript(sourceCode); | 673 v8::Local<v8::Value> object = compileAndRunScript(sourceCode, corsStatus); |
674 | 674 |
675 m_sourceURL = savedSourceURL; | 675 m_sourceURL = savedSourceURL; |
676 | 676 |
677 if (object.IsEmpty()) | 677 if (object.IsEmpty()) |
678 return ScriptValue(); | 678 return ScriptValue(); |
679 | 679 |
680 return ScriptValue(object); | 680 return ScriptValue(object); |
681 } | 681 } |
682 | 682 |
683 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 683 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
(...skipping 24 matching lines...) Expand all Loading... |
708 v8Results = evaluateHandleScope.Close(resultArray); | 708 v8Results = evaluateHandleScope.Close(resultArray); |
709 } | 709 } |
710 | 710 |
711 if (results && !v8Results.IsEmpty()) { | 711 if (results && !v8Results.IsEmpty()) { |
712 for (size_t i = 0; i < v8Results->Length(); ++i) | 712 for (size_t i = 0; i < v8Results->Length(); ++i) |
713 results->append(ScriptValue(v8Results->Get(i))); | 713 results->append(ScriptValue(v8Results->Get(i))); |
714 } | 714 } |
715 } | 715 } |
716 | 716 |
717 } // namespace WebCore | 717 } // namespace WebCore |
OLD | NEW |