Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: Source/bindings/v8/ScriptPreprocessor.cpp

Issue 168583005: Remove DOMWrapperWorld::isIsolatedWorldId and DOMWrapperWorld::context (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/ScriptPreprocessor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/v8/ScriptPreprocessor.h" 32 #include "bindings/v8/ScriptPreprocessor.h"
33 33
34 #include "bindings/v8/ScriptController.h" 34 #include "bindings/v8/ScriptController.h"
35 #include "bindings/v8/ScriptSourceCode.h" 35 #include "bindings/v8/ScriptSourceCode.h"
36 #include "bindings/v8/ScriptValue.h" 36 #include "bindings/v8/ScriptValue.h"
37 #include "bindings/v8/V8Binding.h"
37 #include "bindings/v8/V8ScriptRunner.h" 38 #include "bindings/v8/V8ScriptRunner.h"
39 #include "core/frame/Frame.h"
40 #include "core/frame/FrameHost.h"
38 #include "core/frame/PageConsole.h" 41 #include "core/frame/PageConsole.h"
39 #include "wtf/TemporaryChange.h" 42 #include "wtf/TemporaryChange.h"
40 43
41 namespace WebCore { 44 namespace WebCore {
42 45
43 ScriptPreprocessor::ScriptPreprocessor(const ScriptSourceCode& preprocessorSourc eCode, ScriptController& controller, PageConsole& console) 46 ScriptPreprocessor::ScriptPreprocessor(const ScriptSourceCode& preprocessorSourc eCode, Frame* frame)
44 : m_isPreprocessing(false) 47 : m_isolate(V8PerIsolateData::mainThreadIsolate())
48 , m_isPreprocessing(false)
45 { 49 {
50 ASSERT(frame);
46 v8::TryCatch tryCatch; 51 v8::TryCatch tryCatch;
47 tryCatch.SetVerbose(true); 52 tryCatch.SetVerbose(true);
48 Vector<ScriptSourceCode> sources; 53 Vector<ScriptSourceCode> sources;
49 sources.append(preprocessorSourceCode); 54 sources.append(preprocessorSourceCode);
50 Vector<ScriptValue> scriptResults; 55 Vector<ScriptValue> scriptResults;
51 controller.executeScriptInIsolatedWorld(ScriptPreprocessorIsolatedWorldId, s ources, DOMWrapperWorld::mainWorldExtensionGroup, &scriptResults); 56 frame->script().executeScriptInIsolatedWorld(ScriptPreprocessorIsolatedWorld Id, sources, DOMWrapperWorld::mainWorldExtensionGroup, &scriptResults);
52 57
53 if (scriptResults.size() != 1) { 58 if (scriptResults.size() != 1) {
54 console.addMessage(JSMessageSource, ErrorMessageLevel, "ScriptPreprocess or internal error, one ScriptSourceCode must give exactly one result."); 59 frame->host()->console().addMessage(JSMessageSource, ErrorMessageLevel, "ScriptPreprocessor internal error, one ScriptSourceCode must give exactly one r esult.");
55 return; 60 return;
56 } 61 }
57 62
58 ScriptValue preprocessorFunction = scriptResults[0]; 63 ScriptValue preprocessorFunction = scriptResults[0];
59 if (!preprocessorFunction.isFunction()) { 64 if (!preprocessorFunction.isFunction()) {
60 console.addMessage(JSMessageSource, ErrorMessageLevel, "The preprocessor must compile to a function."); 65 frame->host()->console().addMessage(JSMessageSource, ErrorMessageLevel, "The preprocessor must compile to a function.");
61 return; 66 return;
62 } 67 }
63 68
64 m_world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWor ldId, DOMWrapperWorld::mainWorldExtensionGroup); 69 m_world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWor ldId, DOMWrapperWorld::mainWorldExtensionGroup);
65 v8::Local<v8::Context> context = m_world->context(controller); 70 v8::Local<v8::Context> context = toV8Context(m_isolate, frame, m_world.get() );
66 m_isolate = context->GetIsolate();
67 71
68 m_context.set(m_isolate, context); 72 m_context.set(m_isolate, context);
69 m_preprocessorFunction.set(m_isolate, v8::Handle<v8::Function>::Cast(preproc essorFunction.v8Value())); 73 m_preprocessorFunction.set(m_isolate, v8::Handle<v8::Function>::Cast(preproc essorFunction.v8Value()));
70 } 74 }
71 75
72 String ScriptPreprocessor::preprocessSourceCode(const String& sourceCode, const String& sourceName) 76 String ScriptPreprocessor::preprocessSourceCode(const String& sourceCode, const String& sourceName)
73 { 77 {
74 if (!isValid()) 78 if (!isValid())
75 return sourceCode; 79 return sourceCode;
76 80
(...skipping 26 matching lines...) Expand all
103 TemporaryChange<bool> isPreprocessing(m_isPreprocessing, true); 107 TemporaryChange<bool> isPreprocessing(m_isPreprocessing, true);
104 v8::Handle<v8::Value> resultValue = V8ScriptRunner::callAsFunction(m_preproc essorFunction.newLocal(m_isolate), m_context.newLocal(m_isolate)->Global(), WTF_ ARRAY_LENGTH(argv), argv); 108 v8::Handle<v8::Value> resultValue = V8ScriptRunner::callAsFunction(m_preproc essorFunction.newLocal(m_isolate), m_context.newLocal(m_isolate)->Global(), WTF_ ARRAY_LENGTH(argv), argv);
105 109
106 if (!resultValue.IsEmpty() && resultValue->IsString()) 110 if (!resultValue.IsEmpty() && resultValue->IsString())
107 return toCoreStringWithNullCheck(resultValue.As<v8::String>()); 111 return toCoreStringWithNullCheck(resultValue.As<v8::String>());
108 112
109 return sourceCode; 113 return sourceCode;
110 } 114 }
111 115
112 } // namespace WebCore 116 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptPreprocessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698