| OLD | NEW |
| 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/child/v8_value_converter_impl.h" | 5 #include "content/child/v8_value_converter_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 V8ValueConverter* V8ValueConverter::create() { | 178 V8ValueConverter* V8ValueConverter::create() { |
| 179 return new V8ValueConverterImpl(); | 179 return new V8ValueConverterImpl(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 V8ValueConverterImpl::V8ValueConverterImpl() | 182 V8ValueConverterImpl::V8ValueConverterImpl() |
| 183 : date_allowed_(false), | 183 : date_allowed_(false), |
| 184 reg_exp_allowed_(false), | 184 reg_exp_allowed_(false), |
| 185 function_allowed_(false), | 185 function_allowed_(false), |
| 186 strip_null_from_objects_(false), | 186 strip_null_from_objects_(false), |
| 187 convert_negative_zero_to_int_(false), |
| 187 avoid_identity_hash_for_testing_(false), | 188 avoid_identity_hash_for_testing_(false), |
| 188 strategy_(NULL) {} | 189 strategy_(NULL) {} |
| 189 | 190 |
| 190 void V8ValueConverterImpl::SetDateAllowed(bool val) { | 191 void V8ValueConverterImpl::SetDateAllowed(bool val) { |
| 191 date_allowed_ = val; | 192 date_allowed_ = val; |
| 192 } | 193 } |
| 193 | 194 |
| 194 void V8ValueConverterImpl::SetRegExpAllowed(bool val) { | 195 void V8ValueConverterImpl::SetRegExpAllowed(bool val) { |
| 195 reg_exp_allowed_ = val; | 196 reg_exp_allowed_ = val; |
| 196 } | 197 } |
| 197 | 198 |
| 198 void V8ValueConverterImpl::SetFunctionAllowed(bool val) { | 199 void V8ValueConverterImpl::SetFunctionAllowed(bool val) { |
| 199 function_allowed_ = val; | 200 function_allowed_ = val; |
| 200 } | 201 } |
| 201 | 202 |
| 202 void V8ValueConverterImpl::SetStripNullFromObjects(bool val) { | 203 void V8ValueConverterImpl::SetStripNullFromObjects(bool val) { |
| 203 strip_null_from_objects_ = val; | 204 strip_null_from_objects_ = val; |
| 204 } | 205 } |
| 205 | 206 |
| 207 void V8ValueConverterImpl::SetConvertNegativeZeroToInt(bool val) { |
| 208 convert_negative_zero_to_int_ = val; |
| 209 } |
| 210 |
| 206 void V8ValueConverterImpl::SetStrategy(Strategy* strategy) { | 211 void V8ValueConverterImpl::SetStrategy(Strategy* strategy) { |
| 207 strategy_ = strategy; | 212 strategy_ = strategy; |
| 208 } | 213 } |
| 209 | 214 |
| 210 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Value( | 215 v8::Local<v8::Value> V8ValueConverterImpl::ToV8Value( |
| 211 const base::Value* value, v8::Local<v8::Context> context) const { | 216 const base::Value* value, v8::Local<v8::Context> context) const { |
| 212 v8::Context::Scope context_scope(context); | 217 v8::Context::Scope context_scope(context); |
| 213 v8::EscapableHandleScope handle_scope(context->GetIsolate()); | 218 v8::EscapableHandleScope handle_scope(context->GetIsolate()); |
| 214 return handle_scope.Escape( | 219 return handle_scope.Escape( |
| 215 ToV8ValueImpl(context->GetIsolate(), context->Global(), value)); | 220 ToV8ValueImpl(context->GetIsolate(), context->Global(), value)); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 371 } |
| 367 | 372 |
| 368 if (val->IsInt32()) | 373 if (val->IsInt32()) |
| 369 return base::MakeUnique<base::FundamentalValue>( | 374 return base::MakeUnique<base::FundamentalValue>( |
| 370 val->ToInt32(isolate)->Value()); | 375 val->ToInt32(isolate)->Value()); |
| 371 | 376 |
| 372 if (val->IsNumber()) { | 377 if (val->IsNumber()) { |
| 373 double val_as_double = val.As<v8::Number>()->Value(); | 378 double val_as_double = val.As<v8::Number>()->Value(); |
| 374 if (!std::isfinite(val_as_double)) | 379 if (!std::isfinite(val_as_double)) |
| 375 return nullptr; | 380 return nullptr; |
| 381 // Normally, this would be an integer, and fall into IsInt32(). But if the |
| 382 // value is -0, it's treated internally as a double. Consumers are allowed |
| 383 // to ignore this esoterica and treat it as an integer. |
| 384 if (convert_negative_zero_to_int_ && val_as_double == 0.0) |
| 385 return base::MakeUnique<base::FundamentalValue>(0); |
| 376 return base::MakeUnique<base::FundamentalValue>(val_as_double); | 386 return base::MakeUnique<base::FundamentalValue>(val_as_double); |
| 377 } | 387 } |
| 378 | 388 |
| 379 if (val->IsString()) { | 389 if (val->IsString()) { |
| 380 v8::String::Utf8Value utf8(val); | 390 v8::String::Utf8Value utf8(val); |
| 381 return base::MakeUnique<base::StringValue>( | 391 return base::MakeUnique<base::StringValue>( |
| 382 std::string(*utf8, utf8.length())); | 392 std::string(*utf8, utf8.length())); |
| 383 } | 393 } |
| 384 | 394 |
| 385 if (val->IsUndefined()) { | 395 if (val->IsUndefined()) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 continue; | 618 continue; |
| 609 | 619 |
| 610 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), | 620 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), |
| 611 std::move(child)); | 621 std::move(child)); |
| 612 } | 622 } |
| 613 | 623 |
| 614 return std::move(result); | 624 return std::move(result); |
| 615 } | 625 } |
| 616 | 626 |
| 617 } // namespace content | 627 } // namespace content |
| OLD | NEW |