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

Side by Side Diff: content/renderer/v8_value_converter_impl.cc

Issue 753523002: remove some calls to to-be-deprecated v8::Value::To* functions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/v8_value_converter_impl.h" 5 #include "content/renderer/v8_value_converter_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 CHECK(!val.IsEmpty()); 289 CHECK(!val.IsEmpty());
290 290
291 FromV8ValueState::Level state_level(state); 291 FromV8ValueState::Level state_level(state);
292 if (state->HasReachedMaxRecursionDepth()) 292 if (state->HasReachedMaxRecursionDepth())
293 return NULL; 293 return NULL;
294 294
295 if (val->IsNull()) 295 if (val->IsNull())
296 return base::Value::CreateNullValue(); 296 return base::Value::CreateNullValue();
297 297
298 if (val->IsBoolean()) 298 if (val->IsBoolean())
299 return new base::FundamentalValue(val->ToBoolean()->Value()); 299 return new base::FundamentalValue(val->ToBoolean(isolate)->Value());
300 300
301 if (val->IsNumber() && strategy_) { 301 if (val->IsNumber() && strategy_) {
302 base::Value* out = NULL; 302 base::Value* out = NULL;
303 if (strategy_->FromV8Number(val->ToNumber(), &out)) 303 if (strategy_->FromV8Number(val.As<v8::Number>(), &out))
304 return out; 304 return out;
305 } 305 }
306 306
307 if (val->IsInt32()) 307 if (val->IsInt32())
308 return new base::FundamentalValue(val->ToInt32()->Value()); 308 return new base::FundamentalValue(val->ToInt32(isolate)->Value());
309 309
310 if (val->IsNumber()) { 310 if (val->IsNumber()) {
311 double val_as_double = val->ToNumber()->Value(); 311 double val_as_double = val.As<v8::Number>()->Value();
312 if (!base::IsFinite(val_as_double)) 312 if (!base::IsFinite(val_as_double))
313 return NULL; 313 return NULL;
314 return new base::FundamentalValue(val_as_double); 314 return new base::FundamentalValue(val_as_double);
315 } 315 }
316 316
317 if (val->IsString()) { 317 if (val->IsString()) {
318 v8::String::Utf8Value utf8(val->ToString()); 318 v8::String::Utf8Value utf8(val);
319 return new base::StringValue(std::string(*utf8, utf8.length())); 319 return new base::StringValue(std::string(*utf8, utf8.length()));
320 } 320 }
321 321
322 if (val->IsUndefined()) { 322 if (val->IsUndefined()) {
323 if (strategy_) { 323 if (strategy_) {
324 base::Value* out = NULL; 324 base::Value* out = NULL;
325 if (strategy_->FromV8Undefined(&out)) 325 if (strategy_->FromV8Undefined(&out))
326 return out; 326 return out;
327 } 327 }
328 // JSON.stringify ignores undefined. 328 // JSON.stringify ignores undefined.
329 return NULL; 329 return NULL;
330 } 330 }
331 331
332 if (val->IsDate()) { 332 if (val->IsDate()) {
333 if (!date_allowed_) 333 if (!date_allowed_)
334 // JSON.stringify would convert this to a string, but an object is more 334 // JSON.stringify would convert this to a string, but an object is more
335 // consistent within this class. 335 // consistent within this class.
336 return FromV8Object(val->ToObject(), state, isolate); 336 return FromV8Object(val->ToObject(isolate), state, isolate);
337 v8::Date* date = v8::Date::Cast(*val); 337 v8::Date* date = v8::Date::Cast(*val);
338 return new base::FundamentalValue(date->ValueOf() / 1000.0); 338 return new base::FundamentalValue(date->ValueOf() / 1000.0);
339 } 339 }
340 340
341 if (val->IsRegExp()) { 341 if (val->IsRegExp()) {
342 if (!reg_exp_allowed_) 342 if (!reg_exp_allowed_)
343 // JSON.stringify converts to an object. 343 // JSON.stringify converts to an object.
344 return FromV8Object(val->ToObject(), state, isolate); 344 return FromV8Object(val.As<v8::Object>(), state, isolate);
345 return new base::StringValue(*v8::String::Utf8Value(val->ToString())); 345 return new base::StringValue(*v8::String::Utf8Value(val));
346 } 346 }
347 347
348 // v8::Value doesn't have a ToArray() method for some reason. 348 // v8::Value doesn't have a ToArray() method for some reason.
349 if (val->IsArray()) 349 if (val->IsArray())
350 return FromV8Array(val.As<v8::Array>(), state, isolate); 350 return FromV8Array(val.As<v8::Array>(), state, isolate);
351 351
352 if (val->IsFunction()) { 352 if (val->IsFunction()) {
353 if (!function_allowed_) 353 if (!function_allowed_)
354 // JSON.stringify refuses to convert function(){}. 354 // JSON.stringify refuses to convert function(){}.
355 return NULL; 355 return NULL;
356 return FromV8Object(val->ToObject(), state, isolate); 356 return FromV8Object(val.As<v8::Object>(), state, isolate);
357 } 357 }
358 358
359 if (val->IsArrayBuffer() || val->IsArrayBufferView()) 359 if (val->IsArrayBuffer() || val->IsArrayBufferView())
360 return FromV8ArrayBuffer(val->ToObject(), isolate); 360 return FromV8ArrayBuffer(val.As<v8::Object>(), isolate);
361 361
362 if (val->IsObject()) 362 if (val->IsObject())
363 return FromV8Object(val->ToObject(), state, isolate); 363 return FromV8Object(val.As<v8::Object>(), state, isolate);
364 364
365 LOG(ERROR) << "Unexpected v8 value type encountered."; 365 LOG(ERROR) << "Unexpected v8 value type encountered.";
366 return NULL; 366 return NULL;
367 } 367 }
368 368
369 base::Value* V8ValueConverterImpl::FromV8Array( 369 base::Value* V8ValueConverterImpl::FromV8Array(
370 v8::Handle<v8::Array> val, 370 v8::Handle<v8::Array> val,
371 FromV8ValueState* state, 371 FromV8ValueState* state,
372 v8::Isolate* isolate) const { 372 v8::Isolate* isolate) const {
373 if (!state->UpdateAndCheckUniqueness(val)) 373 if (!state->UpdateAndCheckUniqueness(val))
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 v8::Handle<v8::Value> key(property_names->Get(i)); 500 v8::Handle<v8::Value> key(property_names->Get(i));
501 501
502 // Extend this test to cover more types as necessary and if sensible. 502 // Extend this test to cover more types as necessary and if sensible.
503 if (!key->IsString() && 503 if (!key->IsString() &&
504 !key->IsNumber()) { 504 !key->IsNumber()) {
505 NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) << "\" " 505 NOTREACHED() << "Key \"" << *v8::String::Utf8Value(key) << "\" "
506 "is neither a string nor a number"; 506 "is neither a string nor a number";
507 continue; 507 continue;
508 } 508 }
509 509
510 v8::String::Utf8Value name_utf8(key->ToString()); 510 v8::String::Utf8Value name_utf8(key);
511 511
512 v8::TryCatch try_catch; 512 v8::TryCatch try_catch;
513 v8::Handle<v8::Value> child_v8 = val->Get(key); 513 v8::Handle<v8::Value> child_v8 = val->Get(key);
514 514
515 if (try_catch.HasCaught()) { 515 if (try_catch.HasCaught()) {
516 LOG(WARNING) << "Getter for property " << *name_utf8 516 LOG(WARNING) << "Getter for property " << *name_utf8
517 << " threw an exception."; 517 << " threw an exception.";
518 child_v8 = v8::Null(isolate); 518 child_v8 = v8::Null(isolate);
519 } 519 }
520 520
(...skipping 27 matching lines...) Expand all
548 continue; 548 continue;
549 549
550 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), 550 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
551 child.release()); 551 child.release());
552 } 552 }
553 553
554 return result.release(); 554 return result.release();
555 } 555 }
556 556
557 } // namespace content 557 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/v8_var_converter_unittest.cc ('k') | content/shell/renderer/test_runner/test_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698