Reviewers: jochen (slow),

Description:
Add HeapNumber fast path to v8::Value::{Uint,Int}32Value()

This has the added benefit that these functions are now guaranteed not to throw
when v8::Value::Is{Uint,Int}32() returned true, even when calling into
JavaScript would throw a stack limit error.

BUG=chromium:446097
LOG=y

Please review this at https://codereview.chromium.org/873983003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+4, -4 lines):
  M src/api.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index d1e782f7d35af10bfb47e28b6e3f060449cbe06d..19b877823c339f24fc06fd59093d1007cff8f6a6 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2829,8 +2829,8 @@ Local<Uint32> Value::ToArrayIndex() const {

 int32_t Value::Int32Value() const {
   i::Handle<i::Object> obj = Utils::OpenHandle(this);
-  if (obj->IsSmi()) {
-    return i::Smi::cast(*obj)->value();
+  if (obj->IsNumber()) {
+    return NumberToInt32(*obj);
   } else {
     i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
     LOG_API(isolate, "Int32Value (slow)");
@@ -2930,8 +2930,8 @@ bool Value::SameValue(Handle<Value> that) const {

 uint32_t Value::Uint32Value() const {
   i::Handle<i::Object> obj = Utils::OpenHandle(this);
-  if (obj->IsSmi()) {
-    return i::Smi::cast(*obj)->value();
+  if (obj->IsNumber()) {
+    return NumberToUint32(*obj);
   } else {
     i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
     LOG_API(isolate, "Uint32Value");


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to