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

Unified Diff: src/objects.cc

Issue 1404283002: Unify ToArrayLength conversions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 2b6feb5c828b139d3ada33c35e9dcefe94d64883..f312edc66939293a2864cf567f3467cd5ceab29e 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -715,15 +715,16 @@ bool Object::ToInt32(int32_t* value) {
bool Object::ToUint32(uint32_t* value) {
if (IsSmi()) {
int num = Smi::cast(this)->value();
- if (num >= 0) {
- *value = static_cast<uint32_t>(num);
- return true;
- }
+ if (num < 0) return false;
Camillo Bruni 2015/10/15 13:36:13 yes please :)
Jakob Kummerow 2015/10/15 14:12:06 You're most welcome.
+ *value = static_cast<uint32_t>(num);
+ return true;
}
if (IsHeapNumber()) {
double num = HeapNumber::cast(this)->value();
- if (num >= 0 && FastUI2D(FastD2UI(num)) == num) {
- *value = FastD2UI(num);
+ if (num < 0) return false;
+ uint32_t uint_value = FastD2UI(num);
+ if (FastUI2D(uint_value) == num) {
+ *value = uint_value;
return true;
}
}
@@ -6393,26 +6394,28 @@ bool JSArray::DefineOwnProperty(Isolate* isolate, Handle<JSArray> o,
}
-// TODO(jkummerow): Consider unification with ArrayLengthSetter in accessors.cc.
-bool AnythingToArrayLength(Isolate* isolate, Handle<Object> length_obj,
- uint32_t* output) {
+// Part of ES6 9.4.2.4 ArraySetLength.
+// static
+bool JSArray::AnythingToArrayLength(Isolate* isolate,
+ Handle<Object> length_object,
+ uint32_t* output) {
// Fast path: check numbers and strings that can be converted directly
// and unobservably.
- if (length_obj->ToUint32(output)) return true;
- if (length_obj->IsString() &&
- Handle<String>::cast(length_obj)->AsArrayIndex(output)) {
+ if (length_object->ToUint32(output)) return true;
Toon Verwaest 2015/10/15 12:58:22 Perhaps change to ToArrayLength
Jakob Kummerow 2015/10/15 14:12:06 Done.
+ if (length_object->IsString() &&
+ Handle<String>::cast(length_object)->AsArrayIndex(output)) {
Camillo Bruni 2015/10/15 13:36:13 This case is almost handled in Object::ToUint32 =>
Jakob Kummerow 2015/10/15 14:12:06 Yes -- this is the fast path; everything it handle
return true;
}
// Slow path: follow steps in ES6 9.4.2.4 "ArraySetLength".
// 3. Let newLen be ToUint32(Desc.[[Value]]).
Handle<Object> uint32_v;
- if (!Object::ToUint32(isolate, length_obj).ToHandle(&uint32_v)) {
+ if (!Object::ToUint32(isolate, length_object).ToHandle(&uint32_v)) {
// 4. ReturnIfAbrupt(newLen).
return false;
}
// 5. Let numberLen be ToNumber(Desc.[[Value]]).
Handle<Object> number_v;
- if (!Object::ToNumber(length_obj).ToHandle(&number_v)) {
+ if (!Object::ToNumber(length_object).ToHandle(&number_v)) {
// 6. ReturnIfAbrupt(newLen).
return false;
}
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698