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