| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 | 179 |
| 180 class LookupResult BASE_EMBEDDED { | 180 class LookupResult BASE_EMBEDDED { |
| 181 public: | 181 public: |
| 182 explicit LookupResult(Isolate* isolate) | 182 explicit LookupResult(Isolate* isolate) |
| 183 : isolate_(isolate), | 183 : isolate_(isolate), |
| 184 next_(isolate->top_lookup_result()), | 184 next_(isolate->top_lookup_result()), |
| 185 lookup_type_(NOT_FOUND), | 185 lookup_type_(NOT_FOUND), |
| 186 holder_(NULL), | 186 holder_(NULL), |
| 187 transition_(NULL), | |
| 188 cacheable_(true), | 187 cacheable_(true), |
| 189 details_(NONE, NONEXISTENT, Representation::None()) { | 188 details_(NONE, NONEXISTENT, Representation::None()) { |
| 190 isolate->set_top_lookup_result(this); | 189 isolate->SetTopLookupResult(this); |
| 191 } | 190 } |
| 192 | 191 |
| 193 ~LookupResult() { | 192 ~LookupResult() { |
| 194 ASSERT(isolate()->top_lookup_result() == this); | 193 ASSERT(isolate()->top_lookup_result() == this); |
| 195 isolate()->set_top_lookup_result(next_); | 194 isolate()->SetTopLookupResult(next_); |
| 196 } | 195 } |
| 197 | 196 |
| 198 Isolate* isolate() const { return isolate_; } | 197 Isolate* isolate() const { return isolate_; } |
| 199 | 198 |
| 200 void DescriptorResult(JSObject* holder, PropertyDetails details, int number) { | 199 void DescriptorResult(JSObject* holder, PropertyDetails details, int number) { |
| 201 lookup_type_ = DESCRIPTOR_TYPE; | 200 lookup_type_ = DESCRIPTOR_TYPE; |
| 202 holder_ = holder; | 201 holder_ = holder; |
| 203 transition_ = NULL; | |
| 204 details_ = details; | 202 details_ = details; |
| 205 number_ = number; | 203 number_ = number; |
| 206 } | 204 } |
| 207 | 205 |
| 208 bool CanHoldValue(Handle<Object> value) { | 206 bool CanHoldValue(Handle<Object> value) { |
| 209 if (IsNormal()) return true; | 207 if (IsNormal()) return true; |
| 210 ASSERT(!IsTransition()); | 208 ASSERT(!IsTransition()); |
| 211 return value->FitsRepresentation(details_.representation()); | 209 return value->FitsRepresentation(details_.representation()); |
| 212 } | 210 } |
| 213 | 211 |
| 214 void TransitionResult(JSObject* holder, Map* target) { | 212 void TransitionResult(JSObject* holder, int number) { |
| 215 lookup_type_ = TRANSITION_TYPE; | 213 lookup_type_ = TRANSITION_TYPE; |
| 216 details_ = PropertyDetails(NONE, TRANSITION, Representation::None()); | 214 details_ = PropertyDetails(NONE, TRANSITION, Representation::None()); |
| 217 holder_ = holder; | 215 holder_ = holder; |
| 218 transition_ = target; | 216 number_ = number; |
| 219 number_ = 0xAAAA; | |
| 220 } | 217 } |
| 221 | 218 |
| 222 void DictionaryResult(JSObject* holder, int entry) { | 219 void DictionaryResult(JSObject* holder, int entry) { |
| 223 lookup_type_ = DICTIONARY_TYPE; | 220 lookup_type_ = DICTIONARY_TYPE; |
| 224 holder_ = holder; | 221 holder_ = holder; |
| 225 transition_ = NULL; | |
| 226 details_ = holder->property_dictionary()->DetailsAt(entry); | 222 details_ = holder->property_dictionary()->DetailsAt(entry); |
| 227 number_ = entry; | 223 number_ = entry; |
| 228 } | 224 } |
| 229 | 225 |
| 230 void HandlerResult(JSProxy* proxy) { | 226 void HandlerResult(JSProxy* proxy) { |
| 231 lookup_type_ = HANDLER_TYPE; | 227 lookup_type_ = HANDLER_TYPE; |
| 232 holder_ = proxy; | 228 holder_ = proxy; |
| 233 transition_ = NULL; | |
| 234 details_ = PropertyDetails(NONE, HANDLER, Representation::Tagged()); | 229 details_ = PropertyDetails(NONE, HANDLER, Representation::Tagged()); |
| 235 cacheable_ = false; | 230 cacheable_ = false; |
| 236 } | 231 } |
| 237 | 232 |
| 238 void InterceptorResult(JSObject* holder) { | 233 void InterceptorResult(JSObject* holder) { |
| 239 lookup_type_ = INTERCEPTOR_TYPE; | 234 lookup_type_ = INTERCEPTOR_TYPE; |
| 240 holder_ = holder; | 235 holder_ = holder; |
| 241 transition_ = NULL; | |
| 242 details_ = PropertyDetails(NONE, INTERCEPTOR, Representation::Tagged()); | 236 details_ = PropertyDetails(NONE, INTERCEPTOR, Representation::Tagged()); |
| 243 } | 237 } |
| 244 | 238 |
| 245 void NotFound() { | 239 void NotFound() { |
| 246 lookup_type_ = NOT_FOUND; | 240 lookup_type_ = NOT_FOUND; |
| 247 details_ = PropertyDetails(NONE, NONEXISTENT, Representation::None()); | 241 details_ = PropertyDetails(NONE, NONEXISTENT, Representation::None()); |
| 248 holder_ = NULL; | 242 holder_ = NULL; |
| 249 transition_ = NULL; | |
| 250 } | 243 } |
| 251 | 244 |
| 252 JSObject* holder() const { | 245 JSObject* holder() { |
| 253 ASSERT(IsFound()); | 246 ASSERT(IsFound()); |
| 254 return JSObject::cast(holder_); | 247 return JSObject::cast(holder_); |
| 255 } | 248 } |
| 256 | 249 |
| 257 JSProxy* proxy() const { | 250 JSProxy* proxy() { |
| 258 ASSERT(IsHandler()); | 251 ASSERT(IsFound()); |
| 259 return JSProxy::cast(holder_); | 252 return JSProxy::cast(holder_); |
| 260 } | 253 } |
| 261 | 254 |
| 262 PropertyType type() const { | 255 PropertyType type() { |
| 263 ASSERT(IsFound()); | 256 ASSERT(IsFound()); |
| 264 return details_.type(); | 257 return details_.type(); |
| 265 } | 258 } |
| 266 | 259 |
| 267 Representation representation() const { | 260 Representation representation() { |
| 268 ASSERT(IsFound()); | 261 ASSERT(IsFound()); |
| 269 ASSERT(!IsTransition()); | 262 ASSERT(!IsTransition()); |
| 270 ASSERT(details_.type() != NONEXISTENT); | 263 ASSERT(details_.type() != NONEXISTENT); |
| 271 return details_.representation(); | 264 return details_.representation(); |
| 272 } | 265 } |
| 273 | 266 |
| 274 PropertyAttributes GetAttributes() const { | 267 PropertyAttributes GetAttributes() { |
| 275 ASSERT(!IsTransition()); | 268 ASSERT(!IsTransition()); |
| 276 ASSERT(IsFound()); | 269 ASSERT(IsFound()); |
| 277 ASSERT(details_.type() != NONEXISTENT); | 270 ASSERT(details_.type() != NONEXISTENT); |
| 278 return details_.attributes(); | 271 return details_.attributes(); |
| 279 } | 272 } |
| 280 | 273 |
| 281 PropertyDetails GetPropertyDetails() const { | 274 PropertyDetails GetPropertyDetails() { |
| 282 ASSERT(!IsTransition()); | 275 ASSERT(!IsTransition()); |
| 283 return details_; | 276 return details_; |
| 284 } | 277 } |
| 285 | 278 |
| 286 bool IsFastPropertyType() const { | 279 bool IsFastPropertyType() { |
| 287 ASSERT(IsFound()); | 280 ASSERT(IsFound()); |
| 288 return IsTransition() || type() != NORMAL; | 281 return IsTransition() || type() != NORMAL; |
| 289 } | 282 } |
| 290 | 283 |
| 291 // Property callbacks does not include transitions to callbacks. | 284 // Property callbacks does not include transitions to callbacks. |
| 292 bool IsPropertyCallbacks() const { | 285 bool IsPropertyCallbacks() { |
| 293 ASSERT(!(details_.type() == CALLBACKS && !IsFound())); | 286 ASSERT(!(details_.type() == CALLBACKS && !IsFound())); |
| 294 return details_.type() == CALLBACKS; | 287 return details_.type() == CALLBACKS; |
| 295 } | 288 } |
| 296 | 289 |
| 297 bool IsReadOnly() const { | 290 bool IsReadOnly() { |
| 298 ASSERT(IsFound()); | 291 ASSERT(IsFound()); |
| 299 ASSERT(!IsTransition()); | 292 ASSERT(!IsTransition()); |
| 300 ASSERT(details_.type() != NONEXISTENT); | 293 ASSERT(details_.type() != NONEXISTENT); |
| 301 return details_.IsReadOnly(); | 294 return details_.IsReadOnly(); |
| 302 } | 295 } |
| 303 | 296 |
| 304 bool IsField() const { | 297 bool IsField() { |
| 305 ASSERT(!(details_.type() == FIELD && !IsFound())); | 298 ASSERT(!(details_.type() == FIELD && !IsFound())); |
| 306 return details_.type() == FIELD; | 299 return details_.type() == FIELD; |
| 307 } | 300 } |
| 308 | 301 |
| 309 bool IsNormal() const { | 302 bool IsNormal() { |
| 310 ASSERT(!(details_.type() == NORMAL && !IsFound())); | 303 ASSERT(!(details_.type() == NORMAL && !IsFound())); |
| 311 return details_.type() == NORMAL; | 304 return details_.type() == NORMAL; |
| 312 } | 305 } |
| 313 | 306 |
| 314 bool IsConstant() const { | 307 bool IsConstant() { |
| 315 ASSERT(!(details_.type() == CONSTANT && !IsFound())); | 308 ASSERT(!(details_.type() == CONSTANT && !IsFound())); |
| 316 return details_.type() == CONSTANT; | 309 return details_.type() == CONSTANT; |
| 317 } | 310 } |
| 318 | 311 |
| 319 bool IsConstantFunction() const { | 312 bool IsConstantFunction() { |
| 320 return IsConstant() && GetValue()->IsJSFunction(); | 313 return IsConstant() && GetValue()->IsJSFunction(); |
| 321 } | 314 } |
| 322 | 315 |
| 323 bool IsDontDelete() const { return details_.IsDontDelete(); } | 316 bool IsDontDelete() { return details_.IsDontDelete(); } |
| 324 bool IsDontEnum() const { return details_.IsDontEnum(); } | 317 bool IsDontEnum() { return details_.IsDontEnum(); } |
| 325 bool IsFound() const { return lookup_type_ != NOT_FOUND; } | 318 bool IsFound() { return lookup_type_ != NOT_FOUND; } |
| 326 bool IsTransition() const { return lookup_type_ == TRANSITION_TYPE; } | 319 bool IsTransition() { return lookup_type_ == TRANSITION_TYPE; } |
| 327 bool IsHandler() const { return lookup_type_ == HANDLER_TYPE; } | 320 bool IsHandler() { return lookup_type_ == HANDLER_TYPE; } |
| 328 bool IsInterceptor() const { return lookup_type_ == INTERCEPTOR_TYPE; } | 321 bool IsInterceptor() { return lookup_type_ == INTERCEPTOR_TYPE; } |
| 329 | 322 |
| 330 // Is the result is a property excluding transitions and the null descriptor? | 323 // Is the result is a property excluding transitions and the null descriptor? |
| 331 bool IsProperty() const { | 324 bool IsProperty() { |
| 332 return IsFound() && !IsTransition(); | 325 return IsFound() && !IsTransition(); |
| 333 } | 326 } |
| 334 | 327 |
| 335 bool IsDataProperty() const { | 328 bool IsDataProperty() { |
| 336 switch (type()) { | 329 switch (type()) { |
| 337 case FIELD: | 330 case FIELD: |
| 338 case NORMAL: | 331 case NORMAL: |
| 339 case CONSTANT: | 332 case CONSTANT: |
| 340 return true; | 333 return true; |
| 341 case CALLBACKS: { | 334 case CALLBACKS: { |
| 342 Object* callback = GetCallbackObject(); | 335 Object* callback = GetCallbackObject(); |
| 343 return callback->IsAccessorInfo() || callback->IsForeign(); | 336 return callback->IsAccessorInfo() || callback->IsForeign(); |
| 344 } | 337 } |
| 345 case HANDLER: | 338 case HANDLER: |
| 346 case INTERCEPTOR: | 339 case INTERCEPTOR: |
| 347 case TRANSITION: | 340 case TRANSITION: |
| 348 case NONEXISTENT: | 341 case NONEXISTENT: |
| 349 return false; | 342 return false; |
| 350 } | 343 } |
| 351 UNREACHABLE(); | 344 UNREACHABLE(); |
| 352 return false; | 345 return false; |
| 353 } | 346 } |
| 354 | 347 |
| 355 bool IsCacheable() const { return cacheable_; } | 348 bool IsCacheable() { return cacheable_; } |
| 356 void DisallowCaching() { cacheable_ = false; } | 349 void DisallowCaching() { cacheable_ = false; } |
| 357 | 350 |
| 358 Object* GetLazyValue() const { | 351 Object* GetLazyValue() { |
| 359 switch (type()) { | 352 switch (type()) { |
| 360 case FIELD: | 353 case FIELD: |
| 361 return holder()->RawFastPropertyAt(GetFieldIndex().field_index()); | 354 return holder()->RawFastPropertyAt(GetFieldIndex().field_index()); |
| 362 case NORMAL: { | 355 case NORMAL: { |
| 363 Object* value; | 356 Object* value; |
| 364 value = holder()->property_dictionary()->ValueAt(GetDictionaryEntry()); | 357 value = holder()->property_dictionary()->ValueAt(GetDictionaryEntry()); |
| 365 if (holder()->IsGlobalObject()) { | 358 if (holder()->IsGlobalObject()) { |
| 366 value = PropertyCell::cast(value)->value(); | 359 value = PropertyCell::cast(value)->value(); |
| 367 } | 360 } |
| 368 return value; | 361 return value; |
| 369 } | 362 } |
| 370 case CONSTANT: | 363 case CONSTANT: |
| 371 return GetConstant(); | 364 return GetConstant(); |
| 372 case CALLBACKS: | 365 case CALLBACKS: |
| 373 case HANDLER: | 366 case HANDLER: |
| 374 case INTERCEPTOR: | 367 case INTERCEPTOR: |
| 375 case TRANSITION: | 368 case TRANSITION: |
| 376 case NONEXISTENT: | 369 case NONEXISTENT: |
| 377 return isolate()->heap()->the_hole_value(); | 370 return isolate()->heap()->the_hole_value(); |
| 378 } | 371 } |
| 379 UNREACHABLE(); | 372 UNREACHABLE(); |
| 380 return NULL; | 373 return NULL; |
| 381 } | 374 } |
| 382 | 375 |
| 383 Map* GetTransitionTarget() const { | 376 Map* GetTransitionTarget(Map* map) { |
| 384 return transition_; | 377 ASSERT(IsTransition()); |
| 378 TransitionArray* transitions = map->transitions(); |
| 379 return transitions->GetTarget(number_); |
| 385 } | 380 } |
| 386 | 381 |
| 387 PropertyDetails GetTransitionDetails() const { | 382 Map* GetTransitionTarget() { |
| 388 ASSERT(IsTransition()); | 383 return GetTransitionTarget(holder()->map()); |
| 389 return transition_->GetLastDescriptorDetails(); | |
| 390 } | 384 } |
| 391 | 385 |
| 392 bool IsTransitionToField() const { | 386 PropertyDetails GetTransitionDetails(Map* map) { |
| 393 return IsTransition() && GetTransitionDetails().type() == FIELD; | 387 ASSERT(IsTransition()); |
| 388 TransitionArray* transitions = map->transitions(); |
| 389 return transitions->GetTargetDetails(number_); |
| 394 } | 390 } |
| 395 | 391 |
| 396 bool IsTransitionToConstant() const { | 392 PropertyDetails GetTransitionDetails() { |
| 397 return IsTransition() && GetTransitionDetails().type() == CONSTANT; | 393 return GetTransitionDetails(holder()->map()); |
| 398 } | 394 } |
| 399 | 395 |
| 400 int GetDescriptorIndex() const { | 396 bool IsTransitionToField(Map* map) { |
| 397 return IsTransition() && GetTransitionDetails(map).type() == FIELD; |
| 398 } |
| 399 |
| 400 bool IsTransitionToConstant(Map* map) { |
| 401 return IsTransition() && GetTransitionDetails(map).type() == CONSTANT; |
| 402 } |
| 403 |
| 404 Map* GetTransitionMap() { |
| 405 ASSERT(IsTransition()); |
| 406 return Map::cast(GetValue()); |
| 407 } |
| 408 |
| 409 Map* GetTransitionMapFromMap(Map* map) { |
| 410 ASSERT(IsTransition()); |
| 411 return map->transitions()->GetTarget(number_); |
| 412 } |
| 413 |
| 414 int GetTransitionIndex() { |
| 415 ASSERT(IsTransition()); |
| 416 return number_; |
| 417 } |
| 418 |
| 419 int GetDescriptorIndex() { |
| 401 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); | 420 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
| 402 return number_; | 421 return number_; |
| 403 } | 422 } |
| 404 | 423 |
| 405 PropertyIndex GetFieldIndex() const { | 424 PropertyIndex GetFieldIndex() { |
| 406 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); | 425 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
| 407 return PropertyIndex::NewFieldIndex(GetFieldIndexFromMap(holder()->map())); | 426 return PropertyIndex::NewFieldIndex(GetFieldIndexFromMap(holder()->map())); |
| 408 } | 427 } |
| 409 | 428 |
| 410 int GetLocalFieldIndexFromMap(Map* map) const { | 429 int GetLocalFieldIndexFromMap(Map* map) { |
| 411 return GetFieldIndexFromMap(map) - map->inobject_properties(); | 430 return GetFieldIndexFromMap(map) - map->inobject_properties(); |
| 412 } | 431 } |
| 413 | 432 |
| 414 int GetDictionaryEntry() const { | 433 int GetDictionaryEntry() { |
| 415 ASSERT(lookup_type_ == DICTIONARY_TYPE); | 434 ASSERT(lookup_type_ == DICTIONARY_TYPE); |
| 416 return number_; | 435 return number_; |
| 417 } | 436 } |
| 418 | 437 |
| 419 JSFunction* GetConstantFunction() const { | 438 JSFunction* GetConstantFunction() { |
| 420 ASSERT(type() == CONSTANT); | 439 ASSERT(type() == CONSTANT); |
| 421 return JSFunction::cast(GetValue()); | 440 return JSFunction::cast(GetValue()); |
| 422 } | 441 } |
| 423 | 442 |
| 424 Object* GetConstantFromMap(Map* map) const { | 443 Object* GetConstantFromMap(Map* map) { |
| 425 ASSERT(type() == CONSTANT); | 444 ASSERT(type() == CONSTANT); |
| 426 return GetValueFromMap(map); | 445 return GetValueFromMap(map); |
| 427 } | 446 } |
| 428 | 447 |
| 429 JSFunction* GetConstantFunctionFromMap(Map* map) const { | 448 JSFunction* GetConstantFunctionFromMap(Map* map) { |
| 430 return JSFunction::cast(GetConstantFromMap(map)); | 449 return JSFunction::cast(GetConstantFromMap(map)); |
| 431 } | 450 } |
| 432 | 451 |
| 433 Object* GetConstant() const { | 452 Object* GetConstant() { |
| 434 ASSERT(type() == CONSTANT); | 453 ASSERT(type() == CONSTANT); |
| 435 return GetValue(); | 454 return GetValue(); |
| 436 } | 455 } |
| 437 | 456 |
| 438 Object* GetCallbackObject() const { | 457 Object* GetCallbackObject() { |
| 439 ASSERT(type() == CALLBACKS && !IsTransition()); | 458 ASSERT(type() == CALLBACKS && !IsTransition()); |
| 440 return GetValue(); | 459 return GetValue(); |
| 441 } | 460 } |
| 442 | 461 |
| 443 #ifdef OBJECT_PRINT | 462 #ifdef OBJECT_PRINT |
| 444 void Print(FILE* out); | 463 void Print(FILE* out); |
| 445 #endif | 464 #endif |
| 446 | 465 |
| 447 Object* GetValue() const { | 466 Object* GetValue() { |
| 448 if (lookup_type_ == DESCRIPTOR_TYPE) { | 467 if (lookup_type_ == DESCRIPTOR_TYPE) { |
| 449 return GetValueFromMap(holder()->map()); | 468 return GetValueFromMap(holder()->map()); |
| 450 } | 469 } |
| 451 // In the dictionary case, the data is held in the value field. | 470 // In the dictionary case, the data is held in the value field. |
| 452 ASSERT(lookup_type_ == DICTIONARY_TYPE); | 471 ASSERT(lookup_type_ == DICTIONARY_TYPE); |
| 453 return holder()->GetNormalizedProperty(this); | 472 return holder()->GetNormalizedProperty(this); |
| 454 } | 473 } |
| 455 | 474 |
| 456 Object* GetValueFromMap(Map* map) const { | 475 Object* GetValueFromMap(Map* map) const { |
| 457 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); | 476 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 475 enum { | 494 enum { |
| 476 NOT_FOUND, | 495 NOT_FOUND, |
| 477 DESCRIPTOR_TYPE, | 496 DESCRIPTOR_TYPE, |
| 478 TRANSITION_TYPE, | 497 TRANSITION_TYPE, |
| 479 DICTIONARY_TYPE, | 498 DICTIONARY_TYPE, |
| 480 HANDLER_TYPE, | 499 HANDLER_TYPE, |
| 481 INTERCEPTOR_TYPE | 500 INTERCEPTOR_TYPE |
| 482 } lookup_type_; | 501 } lookup_type_; |
| 483 | 502 |
| 484 JSReceiver* holder_; | 503 JSReceiver* holder_; |
| 485 Map* transition_; | |
| 486 int number_; | 504 int number_; |
| 487 bool cacheable_; | 505 bool cacheable_; |
| 488 PropertyDetails details_; | 506 PropertyDetails details_; |
| 489 }; | 507 }; |
| 490 | 508 |
| 491 | 509 |
| 492 } } // namespace v8::internal | 510 } } // namespace v8::internal |
| 493 | 511 |
| 494 #endif // V8_PROPERTY_H_ | 512 #endif // V8_PROPERTY_H_ |
| OLD | NEW |