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

Side by Side Diff: src/api.cc

Issue 1303093004: Fix a segment-fault caused by Value::IntegerValue Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 | « AUTHORS ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project 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 "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 3246 matching lines...) Expand 10 before | Expand all | Expand 10 after
3257 return NumberValue(ContextFromHeapObject(obj)) 3257 return NumberValue(ContextFromHeapObject(obj))
3258 .FromMaybe(std::numeric_limits<double>::quiet_NaN()); 3258 .FromMaybe(std::numeric_limits<double>::quiet_NaN());
3259 } 3259 }
3260 3260
3261 3261
3262 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const { 3262 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
3263 auto obj = Utils::OpenHandle(this); 3263 auto obj = Utils::OpenHandle(this);
3264 i::Handle<i::Object> num; 3264 i::Handle<i::Object> num;
3265 if (obj->IsNumber()) { 3265 if (obj->IsNumber()) {
3266 num = obj; 3266 num = obj;
3267 return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value())
3268 : static_cast<int64_t>(num->Number()));
3267 } else { 3269 } else {
3268 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); 3270 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t);
3269 has_pending_exception = 3271 has_pending_exception =
jochen (gone - plz use gerrit) 2015/09/09 14:16:59 can you pull the if() case in here instead of dupl
noordhuis 2015/09/09 23:35:56 That pessimizes the common case when the input is
3270 !i::Execution::ToInteger(isolate, obj).ToHandle(&num); 3272 !i::Execution::ToInteger(isolate, obj).ToHandle(&num);
3271 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t); 3273 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t);
3274 return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value())
3275 : static_cast<int64_t>(num->Number()));
3272 } 3276 }
3273 return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value())
3274 : static_cast<int64_t>(num->Number()));
3275 } 3277 }
3276 3278
3277 3279
3278 int64_t Value::IntegerValue() const { 3280 int64_t Value::IntegerValue() const {
3279 auto obj = Utils::OpenHandle(this); 3281 auto obj = Utils::OpenHandle(this);
3280 if (obj->IsNumber()) { 3282 if (obj->IsNumber()) {
3281 if (obj->IsSmi()) { 3283 if (obj->IsSmi()) {
3282 return i::Smi::cast(*obj)->value(); 3284 return i::Smi::cast(*obj)->value();
3283 } else { 3285 } else {
3284 return static_cast<int64_t>(obj->Number()); 3286 return static_cast<int64_t>(obj->Number());
(...skipping 5118 matching lines...) Expand 10 before | Expand all | Expand 10 after
8403 Address callback_address = 8405 Address callback_address =
8404 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8406 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8405 VMState<EXTERNAL> state(isolate); 8407 VMState<EXTERNAL> state(isolate);
8406 ExternalCallbackScope call_scope(isolate, callback_address); 8408 ExternalCallbackScope call_scope(isolate, callback_address);
8407 callback(info); 8409 callback(info);
8408 } 8410 }
8409 8411
8410 8412
8411 } // namespace internal 8413 } // namespace internal
8412 } // namespace v8 8414 } // namespace v8
OLDNEW
« no previous file with comments | « AUTHORS ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698