OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 len = kMaxSafeInteger; | 211 len = kMaxSafeInteger; |
212 } | 212 } |
213 return isolate->factory()->NewNumber(len); | 213 return isolate->factory()->NewNumber(len); |
214 } | 214 } |
215 | 215 |
216 | 216 |
217 bool Object::BooleanValue() { | 217 bool Object::BooleanValue() { |
218 if (IsBoolean()) return IsTrue(); | 218 if (IsBoolean()) return IsTrue(); |
219 if (IsSmi()) return Smi::cast(this)->value() != 0; | 219 if (IsSmi()) return Smi::cast(this)->value() != 0; |
220 if (IsUndefined() || IsNull()) return false; | 220 if (IsUndefined() || IsNull()) return false; |
221 if (IsUndetectableObject()) return false; // Undetectable object is false. | 221 if (IsUndetectable()) return false; // Undetectable object is false. |
222 if (IsString()) return String::cast(this)->length() != 0; | 222 if (IsString()) return String::cast(this)->length() != 0; |
223 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 223 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
224 return true; | 224 return true; |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 namespace { | 228 namespace { |
229 | 229 |
230 // TODO(bmeurer): Maybe we should introduce a marker interface Number, | 230 // TODO(bmeurer): Maybe we should introduce a marker interface Number, |
231 // where we put all these methods at some point? | 231 // where we put all these methods at some point? |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 // static | 285 // static |
286 Maybe<bool> Object::Equals(Handle<Object> x, Handle<Object> y) { | 286 Maybe<bool> Object::Equals(Handle<Object> x, Handle<Object> y) { |
287 while (true) { | 287 while (true) { |
288 if (x->IsNumber()) { | 288 if (x->IsNumber()) { |
289 if (y->IsNumber()) { | 289 if (y->IsNumber()) { |
290 return Just(NumberEquals(x, y)); | 290 return Just(NumberEquals(x, y)); |
291 } else if (y->IsBoolean()) { | 291 } else if (y->IsBoolean()) { |
292 return Just(NumberEquals(*x, Handle<Oddball>::cast(y)->to_number())); | 292 return Just(NumberEquals(*x, Handle<Oddball>::cast(y)->to_number())); |
293 } else if (y->IsString()) { | 293 } else if (y->IsString()) { |
294 return Just(NumberEquals(x, String::ToNumber(Handle<String>::cast(y)))); | 294 return Just(NumberEquals(x, String::ToNumber(Handle<String>::cast(y)))); |
295 } else if (y->IsJSReceiver() && !y->IsUndetectableObject()) { | 295 } else if (y->IsJSReceiver() && !y->IsUndetectable()) { |
296 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) | 296 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) |
297 .ToHandle(&y)) { | 297 .ToHandle(&y)) { |
298 return Nothing<bool>(); | 298 return Nothing<bool>(); |
299 } | 299 } |
300 } else { | 300 } else { |
301 return Just(false); | 301 return Just(false); |
302 } | 302 } |
303 } else if (x->IsString()) { | 303 } else if (x->IsString()) { |
304 if (y->IsString()) { | 304 if (y->IsString()) { |
305 return Just( | 305 return Just( |
306 String::Equals(Handle<String>::cast(x), Handle<String>::cast(y))); | 306 String::Equals(Handle<String>::cast(x), Handle<String>::cast(y))); |
307 } else if (y->IsNumber()) { | 307 } else if (y->IsNumber()) { |
308 x = String::ToNumber(Handle<String>::cast(x)); | 308 x = String::ToNumber(Handle<String>::cast(x)); |
309 return Just(NumberEquals(x, y)); | 309 return Just(NumberEquals(x, y)); |
310 } else if (y->IsBoolean()) { | 310 } else if (y->IsBoolean()) { |
311 x = String::ToNumber(Handle<String>::cast(x)); | 311 x = String::ToNumber(Handle<String>::cast(x)); |
312 return Just(NumberEquals(*x, Handle<Oddball>::cast(y)->to_number())); | 312 return Just(NumberEquals(*x, Handle<Oddball>::cast(y)->to_number())); |
313 } else if (y->IsJSReceiver() && !y->IsUndetectableObject()) { | 313 } else if (y->IsJSReceiver() && !y->IsUndetectable()) { |
314 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) | 314 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) |
315 .ToHandle(&y)) { | 315 .ToHandle(&y)) { |
316 return Nothing<bool>(); | 316 return Nothing<bool>(); |
317 } | 317 } |
318 } else { | 318 } else { |
319 return Just(false); | 319 return Just(false); |
320 } | 320 } |
321 } else if (x->IsBoolean()) { | 321 } else if (x->IsBoolean()) { |
322 if (y->IsOddball()) { | 322 if (y->IsOddball()) { |
323 return Just(x.is_identical_to(y)); | 323 return Just(x.is_identical_to(y)); |
324 } else if (y->IsNumber()) { | 324 } else if (y->IsNumber()) { |
325 return Just(NumberEquals(Handle<Oddball>::cast(x)->to_number(), *y)); | 325 return Just(NumberEquals(Handle<Oddball>::cast(x)->to_number(), *y)); |
326 } else if (y->IsString()) { | 326 } else if (y->IsString()) { |
327 y = String::ToNumber(Handle<String>::cast(y)); | 327 y = String::ToNumber(Handle<String>::cast(y)); |
328 return Just(NumberEquals(Handle<Oddball>::cast(x)->to_number(), *y)); | 328 return Just(NumberEquals(Handle<Oddball>::cast(x)->to_number(), *y)); |
329 } else if (y->IsJSReceiver() && !y->IsUndetectableObject()) { | 329 } else if (y->IsJSReceiver() && !y->IsUndetectable()) { |
330 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) | 330 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) |
331 .ToHandle(&y)) { | 331 .ToHandle(&y)) { |
332 return Nothing<bool>(); | 332 return Nothing<bool>(); |
333 } | 333 } |
334 x = Oddball::ToNumber(Handle<Oddball>::cast(x)); | 334 x = Oddball::ToNumber(Handle<Oddball>::cast(x)); |
335 } else { | 335 } else { |
336 return Just(false); | 336 return Just(false); |
337 } | 337 } |
338 } else if (x->IsSymbol()) { | 338 } else if (x->IsSymbol()) { |
339 if (y->IsSymbol()) { | 339 if (y->IsSymbol()) { |
340 return Just(x.is_identical_to(y)); | 340 return Just(x.is_identical_to(y)); |
341 } else if (y->IsJSReceiver() && !y->IsUndetectableObject()) { | 341 } else if (y->IsJSReceiver() && !y->IsUndetectable()) { |
342 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) | 342 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) |
343 .ToHandle(&y)) { | 343 .ToHandle(&y)) { |
344 return Nothing<bool>(); | 344 return Nothing<bool>(); |
345 } | 345 } |
346 } else { | 346 } else { |
347 return Just(false); | 347 return Just(false); |
348 } | 348 } |
349 } else if (x->IsSimd128Value()) { | 349 } else if (x->IsSimd128Value()) { |
350 if (y->IsSimd128Value()) { | 350 if (y->IsSimd128Value()) { |
351 return Just(Simd128Value::Equals(Handle<Simd128Value>::cast(x), | 351 return Just(Simd128Value::Equals(Handle<Simd128Value>::cast(x), |
352 Handle<Simd128Value>::cast(y))); | 352 Handle<Simd128Value>::cast(y))); |
353 } else if (y->IsJSReceiver() && !y->IsUndetectableObject()) { | 353 } else if (y->IsJSReceiver() && !y->IsUndetectable()) { |
354 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) | 354 if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(y)) |
355 .ToHandle(&y)) { | 355 .ToHandle(&y)) { |
356 return Nothing<bool>(); | 356 return Nothing<bool>(); |
357 } | 357 } |
358 } else { | 358 } else { |
359 return Just(false); | 359 return Just(false); |
360 } | 360 } |
361 } else if (x->IsJSReceiver() && !x->IsUndetectableObject()) { | 361 } else if (x->IsJSReceiver() && !x->IsUndetectable()) { |
362 if (y->IsJSReceiver()) { | 362 if (y->IsJSReceiver()) { |
363 return Just(x.is_identical_to(y)); | 363 return Just(x.is_identical_to(y)); |
364 } else if (y->IsNull() || y->IsUndefined()) { | 364 } else if (y->IsNull() || y->IsUndefined()) { |
365 return Just(false); | 365 return Just(false); |
366 } else if (y->IsBoolean()) { | 366 } else if (y->IsBoolean()) { |
367 y = Oddball::ToNumber(Handle<Oddball>::cast(y)); | 367 y = Oddball::ToNumber(Handle<Oddball>::cast(y)); |
368 } else if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(x)) | 368 } else if (!JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(x)) |
369 .ToHandle(&x)) { | 369 .ToHandle(&x)) { |
370 return Nothing<bool>(); | 370 return Nothing<bool>(); |
371 } | 371 } |
372 } else { | 372 } else { |
373 return Just( | 373 return Just(x->IsUndetectable() && y->IsUndetectable()); |
374 (x->IsNull() || x->IsUndefined() || x->IsUndetectableObject()) && | |
Michael Achenbach
2016/03/03 08:07:06
This change is rubber-stamped.
Benedikt Meurer
2016/03/03 08:09:44
This is the same change that Toon did earlier for
| |
375 (y->IsNull() || y->IsUndefined() || y->IsUndetectableObject())); | |
376 } | 374 } |
377 } | 375 } |
378 } | 376 } |
379 | 377 |
380 | 378 |
381 bool Object::StrictEquals(Object* that) { | 379 bool Object::StrictEquals(Object* that) { |
382 if (this->IsNumber()) { | 380 if (this->IsNumber()) { |
383 if (!that->IsNumber()) return false; | 381 if (!that->IsNumber()) return false; |
384 return NumberEquals(this, that); | 382 return NumberEquals(this, that); |
385 } else if (this->IsString()) { | 383 } else if (this->IsString()) { |
386 if (!that->IsString()) return false; | 384 if (!that->IsString()) return false; |
387 return String::cast(this)->Equals(String::cast(that)); | 385 return String::cast(this)->Equals(String::cast(that)); |
388 } else if (this->IsSimd128Value()) { | 386 } else if (this->IsSimd128Value()) { |
389 if (!that->IsSimd128Value()) return false; | 387 if (!that->IsSimd128Value()) return false; |
390 return Simd128Value::cast(this)->Equals(Simd128Value::cast(that)); | 388 return Simd128Value::cast(this)->Equals(Simd128Value::cast(that)); |
391 } | 389 } |
392 return this == that; | 390 return this == that; |
393 } | 391 } |
394 | 392 |
395 | 393 |
396 // static | 394 // static |
397 Handle<String> Object::TypeOf(Isolate* isolate, Handle<Object> object) { | 395 Handle<String> Object::TypeOf(Isolate* isolate, Handle<Object> object) { |
398 if (object->IsNumber()) return isolate->factory()->number_string(); | 396 if (object->IsNumber()) return isolate->factory()->number_string(); |
399 if (object->IsOddball()) return handle(Oddball::cast(*object)->type_of()); | 397 if (object->IsOddball()) return handle(Oddball::cast(*object)->type_of()); |
400 if (object->IsUndetectableObject()) { | 398 if (object->IsUndetectable()) { |
401 return isolate->factory()->undefined_string(); | 399 return isolate->factory()->undefined_string(); |
402 } | 400 } |
403 if (object->IsString()) return isolate->factory()->string_string(); | 401 if (object->IsString()) return isolate->factory()->string_string(); |
404 if (object->IsSymbol()) return isolate->factory()->symbol_string(); | 402 if (object->IsSymbol()) return isolate->factory()->symbol_string(); |
405 if (object->IsString()) return isolate->factory()->string_string(); | 403 if (object->IsString()) return isolate->factory()->string_string(); |
406 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \ | 404 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \ |
407 if (object->Is##Type()) return isolate->factory()->type##_string(); | 405 if (object->Is##Type()) return isolate->factory()->type##_string(); |
408 SIMD128_TYPES(SIMD128_TYPE) | 406 SIMD128_TYPES(SIMD128_TYPE) |
409 #undef SIMD128_TYPE | 407 #undef SIMD128_TYPE |
410 if (object->IsCallable()) return isolate->factory()->function_string(); | 408 if (object->IsCallable()) return isolate->factory()->function_string(); |
(...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1927 } | 1925 } |
1928 case JS_GENERATOR_OBJECT_TYPE: { | 1926 case JS_GENERATOR_OBJECT_TYPE: { |
1929 accumulator->Add("<JS Generator>"); | 1927 accumulator->Add("<JS Generator>"); |
1930 break; | 1928 break; |
1931 } | 1929 } |
1932 case JS_MODULE_TYPE: { | 1930 case JS_MODULE_TYPE: { |
1933 accumulator->Add("<JS Module>"); | 1931 accumulator->Add("<JS Module>"); |
1934 break; | 1932 break; |
1935 } | 1933 } |
1936 // All other JSObjects are rather similar to each other (JSObject, | 1934 // All other JSObjects are rather similar to each other (JSObject, |
1937 // JSGlobalProxy, JSGlobalObject, JSUndetectableObject, JSValue). | 1935 // JSGlobalProxy, JSGlobalObject, JSUndetectable, JSValue). |
1938 default: { | 1936 default: { |
1939 Map* map_of_this = map(); | 1937 Map* map_of_this = map(); |
1940 Heap* heap = GetHeap(); | 1938 Heap* heap = GetHeap(); |
1941 Object* constructor = map_of_this->GetConstructor(); | 1939 Object* constructor = map_of_this->GetConstructor(); |
1942 bool printed = false; | 1940 bool printed = false; |
1943 if (constructor->IsHeapObject() && | 1941 if (constructor->IsHeapObject() && |
1944 !heap->Contains(HeapObject::cast(constructor))) { | 1942 !heap->Contains(HeapObject::cast(constructor))) { |
1945 accumulator->Add("!!!INVALID CONSTRUCTOR!!!"); | 1943 accumulator->Add("!!!INVALID CONSTRUCTOR!!!"); |
1946 } else { | 1944 } else { |
1947 bool global_object = IsJSGlobalProxy(); | 1945 bool global_object = IsJSGlobalProxy(); |
(...skipping 17823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19771 if (cell->value() != *new_value) { | 19769 if (cell->value() != *new_value) { |
19772 cell->set_value(*new_value); | 19770 cell->set_value(*new_value); |
19773 Isolate* isolate = cell->GetIsolate(); | 19771 Isolate* isolate = cell->GetIsolate(); |
19774 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19772 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19775 isolate, DependentCode::kPropertyCellChangedGroup); | 19773 isolate, DependentCode::kPropertyCellChangedGroup); |
19776 } | 19774 } |
19777 } | 19775 } |
19778 | 19776 |
19779 } // namespace internal | 19777 } // namespace internal |
19780 } // namespace v8 | 19778 } // namespace v8 |
OLD | NEW |