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

Side by Side Diff: content/renderer/pepper/v8_var_converter.cc

Issue 566463002: Ensure that v8 arrays are always converted to object vars when allowed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | 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 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/v8_var_converter.h" 5 #include "content/renderer/pepper/v8_var_converter.h"
6 6
7 #include <map> 7 #include <map>
8 #include <stack> 8 #include <stack>
9 #include <string> 9 #include <string>
10 10
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 &host_buffer->webkit_buffer(), context->Global(), isolate); 148 &host_buffer->webkit_buffer(), context->Global(), isolate);
149 break; 149 break;
150 } 150 }
151 case PP_VARTYPE_ARRAY: 151 case PP_VARTYPE_ARRAY:
152 *result = v8::Array::New(isolate); 152 *result = v8::Array::New(isolate);
153 break; 153 break;
154 case PP_VARTYPE_DICTIONARY: 154 case PP_VARTYPE_DICTIONARY:
155 *result = v8::Object::New(isolate); 155 *result = v8::Object::New(isolate);
156 break; 156 break;
157 case PP_VARTYPE_OBJECT: { 157 case PP_VARTYPE_OBJECT: {
158 DCHECK(object_vars_allowed == V8VarConverter::kAllowObjectVars); 158 // If object vars are disallowed, we should never be passed an object var
159 // to convert. Also, we should never expect to convert an object var which
160 // is nested inside an array or dictionary.
161 if (object_vars_allowed == V8VarConverter::kDisallowObjectVars ||
162 visited_ids->size() != 0) {
163 NOTREACHED();
164 result->Clear();
165 return false;
166 }
159 scoped_refptr<V8ObjectVar> v8_object_var = V8ObjectVar::FromPPVar(var); 167 scoped_refptr<V8ObjectVar> v8_object_var = V8ObjectVar::FromPPVar(var);
160 if (!v8_object_var.get()) { 168 if (!v8_object_var.get()) {
161 NOTREACHED(); 169 NOTREACHED();
162 result->Clear(); 170 result->Clear();
163 return false; 171 return false;
164 } 172 }
165 *result = v8_object_var->GetHandle(); 173 *result = v8_object_var->GetHandle();
166 break; 174 break;
167 } 175 }
168 case PP_VARTYPE_RESOURCE: 176 case PP_VARTYPE_RESOURCE:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 *result = PP_MakeNull(); 226 *result = PP_MakeNull();
219 } else if (val->IsBoolean() || val->IsBooleanObject()) { 227 } else if (val->IsBoolean() || val->IsBooleanObject()) {
220 *result = PP_MakeBool(PP_FromBool(val->ToBoolean()->Value())); 228 *result = PP_MakeBool(PP_FromBool(val->ToBoolean()->Value()));
221 } else if (val->IsInt32()) { 229 } else if (val->IsInt32()) {
222 *result = PP_MakeInt32(val->ToInt32()->Value()); 230 *result = PP_MakeInt32(val->ToInt32()->Value());
223 } else if (val->IsNumber() || val->IsNumberObject()) { 231 } else if (val->IsNumber() || val->IsNumberObject()) {
224 *result = PP_MakeDouble(val->ToNumber()->Value()); 232 *result = PP_MakeDouble(val->ToNumber()->Value());
225 } else if (val->IsString() || val->IsStringObject()) { 233 } else if (val->IsString() || val->IsStringObject()) {
226 v8::String::Utf8Value utf8(val->ToString()); 234 v8::String::Utf8Value utf8(val->ToString());
227 *result = StringVar::StringToPPVar(std::string(*utf8, utf8.length())); 235 *result = StringVar::StringToPPVar(std::string(*utf8, utf8.length()));
228 } else if (val->IsArray()) {
229 *result = (new ArrayVar())->GetPPVar();
230 } else if (val->IsObject()) { 236 } else if (val->IsObject()) {
237 // For any other v8 objects, the conversion happens as follows:
238 // 1) If the object is an array buffer, return an ArrayBufferVar.
239 // 2) If object vars are allowed, return the object wrapped as a
240 // V8ObjectVar. This is to maintain backward compatibility with
241 // synchronous scripting in Flash.
242 // 3) If the object is an array, return an ArrayVar.
243 // 4) If the object can be converted to a resource, return the ResourceVar.
244 // 5) Otherwise return a DictionaryVar.
231 scoped_ptr<blink::WebArrayBuffer> web_array_buffer( 245 scoped_ptr<blink::WebArrayBuffer> web_array_buffer(
232 blink::WebArrayBufferConverter::createFromV8Value(val, isolate)); 246 blink::WebArrayBufferConverter::createFromV8Value(val, isolate));
233 if (web_array_buffer.get()) { 247 if (web_array_buffer.get()) {
234 scoped_refptr<HostArrayBufferVar> buffer_var( 248 scoped_refptr<HostArrayBufferVar> buffer_var(
235 new HostArrayBufferVar(*web_array_buffer)); 249 new HostArrayBufferVar(*web_array_buffer));
236 *result = buffer_var->GetPPVar(); 250 *result = buffer_var->GetPPVar();
237 } else if (object_vars_allowed == V8VarConverter::kAllowObjectVars) { 251 } else if (object_vars_allowed == V8VarConverter::kAllowObjectVars) {
238 v8::Handle<v8::Object> object = val->ToObject(); 252 v8::Handle<v8::Object> object = val->ToObject();
239 *result = content::HostGlobals::Get()-> 253 *result = content::HostGlobals::Get()->
240 host_var_tracker()->V8ObjectVarForV8Object(instance, object); 254 host_var_tracker()->V8ObjectVarForV8Object(instance, object);
255 } else if (val->IsArray()) {
256 *result = (new ArrayVar())->GetPPVar();
241 } else { 257 } else {
242 bool was_resource; 258 bool was_resource;
243 if (!resource_converter->FromV8Value( 259 if (!resource_converter->FromV8Value(
244 val->ToObject(), context, result, &was_resource)) 260 val->ToObject(), context, result, &was_resource))
245 return false; 261 return false;
246 if (!was_resource) { 262 if (!was_resource) {
247 *result = (new DictionaryVar())->GetPPVar(); 263 *result = (new DictionaryVar())->GetPPVar();
248 } 264 }
249 } 265 }
250 } else { 266 } else {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 std::string(*name_utf8, name_utf8.length()), child_var); 611 std::string(*name_utf8, name_utf8.length()), child_var);
596 DCHECK(success); 612 DCHECK(success);
597 } 613 }
598 } 614 }
599 } 615 }
600 *result_var = root; 616 *result_var = root;
601 return true; 617 return true;
602 } 618 }
603 619
604 } // namespace content 620 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698