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

Side by Side Diff: src/JsValue.cpp

Issue 29416579: Issue 5034 - Part 1: Pass a JsValue directly to SetProperty() and return from GetProperty() (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Remove JsValue test Created April 19, 2017, 2:46 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
« no previous file with comments | « src/JsEngine.cpp ('k') | src/Notification.cpp » ('j') | 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 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 const JsContext context(jsEngine); 140 const JsContext context(jsEngine);
141 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(UnwrapValue()); 141 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(UnwrapValue());
142 JsValueList properties = JsValuePtr(new JsValue(jsEngine, object->GetOwnProper tyNames()))->AsList(); 142 JsValueList properties = JsValuePtr(new JsValue(jsEngine, object->GetOwnProper tyNames()))->AsList();
143 std::vector<std::string> result; 143 std::vector<std::string> result;
144 for (const auto& property : properties) 144 for (const auto& property : properties)
145 result.push_back(property->AsString()); 145 result.push_back(property->AsString());
146 return result; 146 return result;
147 } 147 }
148 148
149 149
150 AdblockPlus::JsValuePtr AdblockPlus::JsValue::GetProperty(const std::string& nam e) const 150 AdblockPlus::JsValue AdblockPlus::JsValue::GetProperty(const std::string& name) const
151 { 151 {
152 if (!IsObject()) 152 if (!IsObject())
153 throw new std::runtime_error("Attempting to get property of a non-object"); 153 throw new std::runtime_error("Attempting to get property of a non-object");
154 154
155 const JsContext context(jsEngine); 155 const JsContext context(jsEngine);
156 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->GetIsolate(), nam e); 156 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->GetIsolate(), nam e);
157 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); 157 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue());
158 return JsValuePtr(new JsValue(jsEngine, obj->Get(property))); 158 return JsValue(jsEngine, obj->Get(property));
159 } 159 }
160 160
161 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Handle<v8::V alue> val) 161 void AdblockPlus::JsValue::SetProperty(const std::string& name, v8::Handle<v8::V alue> val)
162 { 162 {
163 if (!IsObject()) 163 if (!IsObject())
164 throw new std::runtime_error("Attempting to set property on a non-object"); 164 throw new std::runtime_error("Attempting to set property on a non-object");
165 165
166 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->GetIsolate(), nam e); 166 v8::Local<v8::String> property = Utils::ToV8String(jsEngine->GetIsolate(), nam e);
167 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue()); 167 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(UnwrapValue());
168 obj->Set(property, val); 168 obj->Set(property, val);
(...skipping 14 matching lines...) Expand all
183 const JsContext context(jsEngine); 183 const JsContext context(jsEngine);
184 SetProperty(name, Utils::ToV8String(jsEngine->GetIsolate(), val)); 184 SetProperty(name, Utils::ToV8String(jsEngine->GetIsolate(), val));
185 } 185 }
186 186
187 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val) 187 void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val)
188 { 188 {
189 const JsContext context(jsEngine); 189 const JsContext context(jsEngine);
190 SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val)); 190 SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val));
191 } 191 }
192 192
193 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValuePtr & val) 193 void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValue& v al)
194 { 194 {
195 const JsContext context(jsEngine); 195 const JsContext context(jsEngine);
196 SetProperty(name, val->UnwrapValue()); 196 SetProperty(name, val.UnwrapValue());
197 } 197 }
198 198
199 void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val) 199 void AdblockPlus::JsValue::SetProperty(const std::string& name, bool val)
200 { 200 {
201 const JsContext context(jsEngine); 201 const JsContext context(jsEngine);
202 SetProperty(name, v8::Boolean::New(val)); 202 SetProperty(name, v8::Boolean::New(val));
203 } 203 }
204 204
205 std::string AdblockPlus::JsValue::GetClass() const 205 std::string AdblockPlus::JsValue::GetClass() const
206 { 206 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const v8::TryCatch tryCatch; 248 const v8::TryCatch tryCatch;
249 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue()); 249 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(UnwrapValue());
250 v8::Local<v8::Value> result = func->Call(thisObj, args.size(), 250 v8::Local<v8::Value> result = func->Call(thisObj, args.size(),
251 args.size() ? &args[0] : nullptr); 251 args.size() ? &args[0] : nullptr);
252 252
253 if (tryCatch.HasCaught()) 253 if (tryCatch.HasCaught())
254 throw JsError(tryCatch.Exception(), tryCatch.Message()); 254 throw JsError(tryCatch.Exception(), tryCatch.Message());
255 255
256 return JsValue(jsEngine, result); 256 return JsValue(jsEngine, result);
257 } 257 }
OLDNEW
« no previous file with comments | « src/JsEngine.cpp ('k') | src/Notification.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld