Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/JsEngine.cpp

Issue 6584950149087232: Issue 1280 - Update v8 (Closed)
Patch Set: use msvs2012, because firstly it should go into our branch Created Oct. 27, 2014, 3:34 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 { 48 {
49 } 49 }
50 50
51 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo) 51 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo)
52 { 52 {
53 JsEnginePtr result(new JsEngine()); 53 JsEnginePtr result(new JsEngine());
54 54
55 const v8::Locker locker(result->isolate); 55 const v8::Locker locker(result->isolate);
56 const v8::HandleScope handleScope; 56 const v8::HandleScope handleScope;
57 57
58 result->context.reset(result->isolate, v8::Context::New()); 58 result->context.reset(result->isolate, v8::Context::New(result->isolate));
59 AdblockPlus::GlobalJsObject::Setup(result, appInfo, 59 AdblockPlus::GlobalJsObject::Setup(result, appInfo,
60 JsValuePtr(new JsValue(result, result->context->Global()))); 60 JsValuePtr(new JsValue(result, v8::Local<v8::Context>::New(result->isolate , result->context)->Global(), JsValue::Private::CtrArg())));
61 return result; 61 return result;
62 } 62 }
63 63
64 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e, 64 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::Evaluate(const std::string& sourc e,
65 const std::string& filename) 65 const std::string& filename)
66 { 66 {
67 const JsContext context(shared_from_this()); 67 const JsContext context(shared_from_this());
68 const v8::TryCatch tryCatch; 68 const v8::TryCatch tryCatch;
69 const v8::Handle<v8::Script> script = CompileScript(source, filename); 69 const v8::Handle<v8::Script> script = CompileScript(source, filename);
70 CheckTryCatch(tryCatch); 70 CheckTryCatch(tryCatch);
71 v8::Local<v8::Value> result = script->Run(); 71 v8::Local<v8::Value> result = script->Run();
72 CheckTryCatch(tryCatch); 72 CheckTryCatch(tryCatch);
73 return JsValuePtr(new JsValue(shared_from_this(), result)); 73 return JsValuePtr(new JsValue(shared_from_this(), result, JsValue::Private::Ct rArg()));
74 } 74 }
75 75
76 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, 76 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName,
77 AdblockPlus::JsEngine::EventCallback callback) 77 AdblockPlus::JsEngine::EventCallback callback)
78 { 78 {
79 eventCallbacks[eventName] = callback; 79 eventCallbacks[eventName] = callback;
80 } 80 }
81 81
82 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName) 82 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName)
83 { 83 {
84 eventCallbacks.erase(eventName); 84 eventCallbacks.erase(eventName);
85 } 85 }
86 86
87 void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName, AdblockPl us::JsValueList& params) 87 void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName, AdblockPl us::JsValueList& params)
88 { 88 {
89 EventMap::iterator it = eventCallbacks.find(eventName); 89 EventMap::iterator it = eventCallbacks.find(eventName);
90 if (it != eventCallbacks.end()) 90 if (it != eventCallbacks.end())
91 it->second(params); 91 it->second(params);
92 } 92 }
93 93
94 void AdblockPlus::JsEngine::Gc() 94 void AdblockPlus::JsEngine::Gc()
95 { 95 {
96 while (!v8::V8::IdleNotification()); 96 while (!v8::V8::IdleNotification());
97 } 97 }
98 98
99 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) 99 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val)
100 { 100 {
101 const JsContext context(shared_from_this()); 101 const JsContext context(shared_from_this());
102 return JsValuePtr(new JsValue(shared_from_this(), 102 return JsValuePtr(new JsValue(shared_from_this(),
103 v8::String::New(val.c_str(), val.length()))); 103 v8::String::New(val.c_str(), val.length()), JsValue::Private::CtrArg()));
104 } 104 }
105 105
106 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val) 106 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(int64_t val)
107 { 107 {
108 const JsContext context(shared_from_this()); 108 const JsContext context(shared_from_this());
109 return JsValuePtr(new JsValue(shared_from_this(), v8::Number::New(val))); 109 return JsValuePtr(new JsValue(shared_from_this(), v8::Number::New(val), JsValu e::Private::CtrArg()));
110 } 110 }
111 111
112 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val) 112 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(bool val)
113 { 113 {
114 const JsContext context(shared_from_this()); 114 const JsContext context(shared_from_this());
115 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val))); 115 return JsValuePtr(new JsValue(shared_from_this(), v8::Boolean::New(val), JsVal ue::Private::CtrArg()));
116 } 116 }
117 117
118 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject() 118 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewObject()
119 { 119 {
120 const JsContext context(shared_from_this()); 120 const JsContext context(shared_from_this());
121 return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New())); 121 return JsValuePtr(new JsValue(shared_from_this(), v8::Object::New(), JsValue:: Private::CtrArg()));
122 } 122 }
123 123
124 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewCallback( 124 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewCallback(
125 v8::InvocationCallback callback) 125 v8::InvocationCallback callback)
126 { 126 {
127 const JsContext context(shared_from_this()); 127 const JsContext context(shared_from_this());
128 128
129 // Note: we are leaking this weak pointer, no obvious way to destroy it when 129 // Note: we are leaking this weak pointer, no obvious way to destroy it when
130 // it's no longer used 130 // it's no longer used
131 std::tr1::weak_ptr<JsEngine>* data = 131 std::tr1::weak_ptr<JsEngine>* data =
132 new std::tr1::weak_ptr<JsEngine>(shared_from_this()); 132 new std::tr1::weak_ptr<JsEngine>(shared_from_this());
133 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback, 133 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback,
134 v8::External::New(data)); 134 v8::External::New(data));
135 return JsValuePtr(new JsValue(shared_from_this(), templ->GetFunction())); 135 return JsValuePtr(new JsValue(shared_from_this(), templ->GetFunction(), JsValu e::Private::CtrArg()));
136 } 136 }
137 137
138 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Argument s& arguments) 138 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::FromArguments(const v8::Argument s& arguments)
139 { 139 {
140 const v8::Local<const v8::External> external = 140 const v8::Local<const v8::External> external =
141 v8::Local<const v8::External>::Cast(arguments.Data()); 141 v8::Local<const v8::External>::Cast(arguments.Data());
142 std::tr1::weak_ptr<JsEngine>* data = 142 std::tr1::weak_ptr<JsEngine>* data =
143 static_cast<std::tr1::weak_ptr<JsEngine>*>(external->Value()); 143 static_cast<std::tr1::weak_ptr<JsEngine>*>(external->Value());
144 JsEnginePtr result = data->lock(); 144 JsEnginePtr result = data->lock();
145 if (!result) 145 if (!result)
146 throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?") ; 146 throw std::runtime_error("Oops, our JsEngine is gone, how did that happen?") ;
147 return result; 147 return result;
148 } 148 }
149 149
150 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum ents& arguments) 150 AdblockPlus::JsValueList AdblockPlus::JsEngine::ConvertArguments(const v8::Argum ents& arguments)
151 { 151 {
152 const JsContext context(shared_from_this()); 152 const JsContext context(shared_from_this());
153 JsValueList list; 153 JsValueList list;
154 for (int i = 0; i < arguments.Length(); i++) 154 for (int i = 0; i < arguments.Length(); i++)
155 list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i]))); 155 list.push_back(JsValuePtr(new JsValue(shared_from_this(), arguments[i], JsVa lue::Private::CtrArg())));
156 return list; 156 return list;
157 } 157 }
158 158
159 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() 159 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem()
160 { 160 {
161 if (!fileSystem) 161 if (!fileSystem)
162 fileSystem.reset(new DefaultFileSystem()); 162 fileSystem.reset(new DefaultFileSystem());
163 return fileSystem; 163 return fileSystem;
164 } 164 }
165 165
(...skipping 27 matching lines...) Expand all
193 return logSystem; 193 return logSystem;
194 } 194 }
195 195
196 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) 196 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val)
197 { 197 {
198 if (!val) 198 if (!val)
199 throw std::runtime_error("LogSystem cannot be null"); 199 throw std::runtime_error("LogSystem cannot be null");
200 200
201 logSystem = val; 201 logSystem = val;
202 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld