OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 7238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7249 } else { | 7249 } else { |
7250 map()->set_non_instance_prototype(false); | 7250 map()->set_non_instance_prototype(false); |
7251 } | 7251 } |
7252 | 7252 |
7253 return SetInstancePrototype(construct_prototype); | 7253 return SetInstancePrototype(construct_prototype); |
7254 } | 7254 } |
7255 | 7255 |
7256 | 7256 |
7257 Object* JSFunction::RemovePrototype() { | 7257 Object* JSFunction::RemovePrototype() { |
7258 Context* global_context = context()->global_context(); | 7258 Context* global_context = context()->global_context(); |
7259 Map* no_prototype_map = shared()->strict_mode() | 7259 Map* no_prototype_map = shared()->is_classic_mode() |
7260 ? global_context->strict_mode_function_without_prototype_map() | 7260 ? global_context->function_without_prototype_map() |
7261 : global_context->function_without_prototype_map(); | 7261 : global_context->strict_mode_function_without_prototype_map(); |
7262 | 7262 |
7263 if (map() == no_prototype_map) { | 7263 if (map() == no_prototype_map) { |
7264 // Be idempotent. | 7264 // Be idempotent. |
7265 return this; | 7265 return this; |
7266 } | 7266 } |
7267 | 7267 |
7268 ASSERT(!shared()->strict_mode() || | 7268 ASSERT(map() == (shared()->is_classic_mode() |
7269 map() == global_context->strict_mode_function_map()); | 7269 ? global_context->function_map() |
7270 ASSERT(shared()->strict_mode() || map() == global_context->function_map()); | 7270 : global_context->strict_mode_function_map())); |
7271 | 7271 |
7272 set_map(no_prototype_map); | 7272 set_map(no_prototype_map); |
7273 set_prototype_or_initial_map(no_prototype_map->GetHeap()->the_hole_value()); | 7273 set_prototype_or_initial_map(no_prototype_map->GetHeap()->the_hole_value()); |
7274 return this; | 7274 return this; |
7275 } | 7275 } |
7276 | 7276 |
7277 | 7277 |
7278 Object* JSFunction::SetInstanceClassName(String* name) { | 7278 Object* JSFunction::SetInstanceClassName(String* name) { |
7279 shared()->set_instance_class_name(name); | 7279 shared()->set_instance_class_name(name); |
7280 return this; | 7280 return this; |
(...skipping 3009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10290 String* string_; | 10290 String* string_; |
10291 uint32_t hash_; | 10291 uint32_t hash_; |
10292 }; | 10292 }; |
10293 | 10293 |
10294 | 10294 |
10295 // StringSharedKeys are used as keys in the eval cache. | 10295 // StringSharedKeys are used as keys in the eval cache. |
10296 class StringSharedKey : public HashTableKey { | 10296 class StringSharedKey : public HashTableKey { |
10297 public: | 10297 public: |
10298 StringSharedKey(String* source, | 10298 StringSharedKey(String* source, |
10299 SharedFunctionInfo* shared, | 10299 SharedFunctionInfo* shared, |
10300 StrictModeFlag strict_mode, | 10300 LanguageMode language_mode, |
10301 int scope_position) | 10301 int scope_position) |
10302 : source_(source), | 10302 : source_(source), |
10303 shared_(shared), | 10303 shared_(shared), |
10304 strict_mode_(strict_mode), | 10304 language_mode_(language_mode), |
10305 scope_position_(scope_position) { } | 10305 scope_position_(scope_position) { } |
10306 | 10306 |
10307 bool IsMatch(Object* other) { | 10307 bool IsMatch(Object* other) { |
10308 if (!other->IsFixedArray()) return false; | 10308 if (!other->IsFixedArray()) return false; |
10309 FixedArray* other_array = FixedArray::cast(other); | 10309 FixedArray* other_array = FixedArray::cast(other); |
10310 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); | 10310 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); |
10311 if (shared != shared_) return false; | 10311 if (shared != shared_) return false; |
10312 int strict_unchecked = Smi::cast(other_array->get(2))->value(); | 10312 int language_unchecked = Smi::cast(other_array->get(2))->value(); |
10313 ASSERT(strict_unchecked == kStrictMode || | 10313 ASSERT(language_unchecked == CLASSIC_MODE || |
10314 strict_unchecked == kNonStrictMode); | 10314 language_unchecked == STRICT_MODE || |
10315 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); | 10315 language_unchecked == EXTENDED_MODE); |
10316 if (strict_mode != strict_mode_) return false; | 10316 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); |
| 10317 if (language_mode != language_mode_) return false; |
10317 int scope_position = Smi::cast(other_array->get(3))->value(); | 10318 int scope_position = Smi::cast(other_array->get(3))->value(); |
10318 if (scope_position != scope_position_) return false; | 10319 if (scope_position != scope_position_) return false; |
10319 String* source = String::cast(other_array->get(1)); | 10320 String* source = String::cast(other_array->get(1)); |
10320 return source->Equals(source_); | 10321 return source->Equals(source_); |
10321 } | 10322 } |
10322 | 10323 |
10323 static uint32_t StringSharedHashHelper(String* source, | 10324 static uint32_t StringSharedHashHelper(String* source, |
10324 SharedFunctionInfo* shared, | 10325 SharedFunctionInfo* shared, |
10325 StrictModeFlag strict_mode, | 10326 LanguageMode language_mode, |
10326 int scope_position) { | 10327 int scope_position) { |
10327 uint32_t hash = source->Hash(); | 10328 uint32_t hash = source->Hash(); |
10328 if (shared->HasSourceCode()) { | 10329 if (shared->HasSourceCode()) { |
10329 // Instead of using the SharedFunctionInfo pointer in the hash | 10330 // Instead of using the SharedFunctionInfo pointer in the hash |
10330 // code computation, we use a combination of the hash of the | 10331 // code computation, we use a combination of the hash of the |
10331 // script source code and the start position of the calling scope. | 10332 // script source code and the start position of the calling scope. |
10332 // We do this to ensure that the cache entries can survive garbage | 10333 // We do this to ensure that the cache entries can survive garbage |
10333 // collection. | 10334 // collection. |
10334 Script* script = Script::cast(shared->script()); | 10335 Script* script = Script::cast(shared->script()); |
10335 hash ^= String::cast(script->source())->Hash(); | 10336 hash ^= String::cast(script->source())->Hash(); |
10336 if (strict_mode == kStrictMode) hash ^= 0x8000; | 10337 if (language_mode == STRICT_MODE) hash ^= 0x8000; |
| 10338 if (language_mode == EXTENDED_MODE) hash ^= 0x0080; |
10337 hash += scope_position; | 10339 hash += scope_position; |
10338 } | 10340 } |
10339 return hash; | 10341 return hash; |
10340 } | 10342 } |
10341 | 10343 |
10342 uint32_t Hash() { | 10344 uint32_t Hash() { |
10343 return StringSharedHashHelper( | 10345 return StringSharedHashHelper( |
10344 source_, shared_, strict_mode_, scope_position_); | 10346 source_, shared_, language_mode_, scope_position_); |
10345 } | 10347 } |
10346 | 10348 |
10347 uint32_t HashForObject(Object* obj) { | 10349 uint32_t HashForObject(Object* obj) { |
10348 FixedArray* other_array = FixedArray::cast(obj); | 10350 FixedArray* other_array = FixedArray::cast(obj); |
10349 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); | 10351 SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0)); |
10350 String* source = String::cast(other_array->get(1)); | 10352 String* source = String::cast(other_array->get(1)); |
10351 int strict_unchecked = Smi::cast(other_array->get(2))->value(); | 10353 int language_unchecked = Smi::cast(other_array->get(2))->value(); |
10352 ASSERT(strict_unchecked == kStrictMode || | 10354 ASSERT(language_unchecked == CLASSIC_MODE || |
10353 strict_unchecked == kNonStrictMode); | 10355 language_unchecked == STRICT_MODE || |
10354 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); | 10356 language_unchecked == EXTENDED_MODE); |
| 10357 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked); |
10355 int scope_position = Smi::cast(other_array->get(3))->value(); | 10358 int scope_position = Smi::cast(other_array->get(3))->value(); |
10356 return StringSharedHashHelper(source, shared, strict_mode, scope_position); | 10359 return StringSharedHashHelper( |
| 10360 source, shared, language_mode, scope_position); |
10357 } | 10361 } |
10358 | 10362 |
10359 MUST_USE_RESULT MaybeObject* AsObject() { | 10363 MUST_USE_RESULT MaybeObject* AsObject() { |
10360 Object* obj; | 10364 Object* obj; |
10361 { MaybeObject* maybe_obj = source_->GetHeap()->AllocateFixedArray(4); | 10365 { MaybeObject* maybe_obj = source_->GetHeap()->AllocateFixedArray(4); |
10362 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 10366 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
10363 } | 10367 } |
10364 FixedArray* other_array = FixedArray::cast(obj); | 10368 FixedArray* other_array = FixedArray::cast(obj); |
10365 other_array->set(0, shared_); | 10369 other_array->set(0, shared_); |
10366 other_array->set(1, source_); | 10370 other_array->set(1, source_); |
10367 other_array->set(2, Smi::FromInt(strict_mode_)); | 10371 other_array->set(2, Smi::FromInt(language_mode_)); |
10368 other_array->set(3, Smi::FromInt(scope_position_)); | 10372 other_array->set(3, Smi::FromInt(scope_position_)); |
10369 return other_array; | 10373 return other_array; |
10370 } | 10374 } |
10371 | 10375 |
10372 private: | 10376 private: |
10373 String* source_; | 10377 String* source_; |
10374 SharedFunctionInfo* shared_; | 10378 SharedFunctionInfo* shared_; |
10375 StrictModeFlag strict_mode_; | 10379 LanguageMode language_mode_; |
10376 int scope_position_; | 10380 int scope_position_; |
10377 }; | 10381 }; |
10378 | 10382 |
10379 | 10383 |
10380 // RegExpKey carries the source and flags of a regular expression as key. | 10384 // RegExpKey carries the source and flags of a regular expression as key. |
10381 class RegExpKey : public HashTableKey { | 10385 class RegExpKey : public HashTableKey { |
10382 public: | 10386 public: |
10383 RegExpKey(String* string, JSRegExp::Flags flags) | 10387 RegExpKey(String* string, JSRegExp::Flags flags) |
10384 : string_(string), | 10388 : string_(string), |
10385 flags_(Smi::FromInt(flags.value())) { } | 10389 flags_(Smi::FromInt(flags.value())) { } |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11521 Object* CompilationCacheTable::Lookup(String* src) { | 11525 Object* CompilationCacheTable::Lookup(String* src) { |
11522 StringKey key(src); | 11526 StringKey key(src); |
11523 int entry = FindEntry(&key); | 11527 int entry = FindEntry(&key); |
11524 if (entry == kNotFound) return GetHeap()->undefined_value(); | 11528 if (entry == kNotFound) return GetHeap()->undefined_value(); |
11525 return get(EntryToIndex(entry) + 1); | 11529 return get(EntryToIndex(entry) + 1); |
11526 } | 11530 } |
11527 | 11531 |
11528 | 11532 |
11529 Object* CompilationCacheTable::LookupEval(String* src, | 11533 Object* CompilationCacheTable::LookupEval(String* src, |
11530 Context* context, | 11534 Context* context, |
11531 StrictModeFlag strict_mode, | 11535 LanguageMode language_mode, |
11532 int scope_position) { | 11536 int scope_position) { |
11533 StringSharedKey key(src, | 11537 StringSharedKey key(src, |
11534 context->closure()->shared(), | 11538 context->closure()->shared(), |
11535 strict_mode, | 11539 language_mode, |
11536 scope_position); | 11540 scope_position); |
11537 int entry = FindEntry(&key); | 11541 int entry = FindEntry(&key); |
11538 if (entry == kNotFound) return GetHeap()->undefined_value(); | 11542 if (entry == kNotFound) return GetHeap()->undefined_value(); |
11539 return get(EntryToIndex(entry) + 1); | 11543 return get(EntryToIndex(entry) + 1); |
11540 } | 11544 } |
11541 | 11545 |
11542 | 11546 |
11543 Object* CompilationCacheTable::LookupRegExp(String* src, | 11547 Object* CompilationCacheTable::LookupRegExp(String* src, |
11544 JSRegExp::Flags flags) { | 11548 JSRegExp::Flags flags) { |
11545 RegExpKey key(src, flags); | 11549 RegExpKey key(src, flags); |
(...skipping 19 matching lines...) Expand all Loading... |
11565 return cache; | 11569 return cache; |
11566 } | 11570 } |
11567 | 11571 |
11568 | 11572 |
11569 MaybeObject* CompilationCacheTable::PutEval(String* src, | 11573 MaybeObject* CompilationCacheTable::PutEval(String* src, |
11570 Context* context, | 11574 Context* context, |
11571 SharedFunctionInfo* value, | 11575 SharedFunctionInfo* value, |
11572 int scope_position) { | 11576 int scope_position) { |
11573 StringSharedKey key(src, | 11577 StringSharedKey key(src, |
11574 context->closure()->shared(), | 11578 context->closure()->shared(), |
11575 value->strict_mode_flag(), | 11579 value->language_mode(), |
11576 scope_position); | 11580 scope_position); |
11577 Object* obj; | 11581 Object* obj; |
11578 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); | 11582 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); |
11579 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 11583 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
11580 } | 11584 } |
11581 | 11585 |
11582 CompilationCacheTable* cache = | 11586 CompilationCacheTable* cache = |
11583 reinterpret_cast<CompilationCacheTable*>(obj); | 11587 reinterpret_cast<CompilationCacheTable*>(obj); |
11584 int entry = cache->FindInsertionEntry(key.Hash()); | 11588 int entry = cache->FindInsertionEntry(key.Hash()); |
11585 | 11589 |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12536 if (break_point_objects()->IsUndefined()) return 0; | 12540 if (break_point_objects()->IsUndefined()) return 0; |
12537 // Single break point. | 12541 // Single break point. |
12538 if (!break_point_objects()->IsFixedArray()) return 1; | 12542 if (!break_point_objects()->IsFixedArray()) return 1; |
12539 // Multiple break points. | 12543 // Multiple break points. |
12540 return FixedArray::cast(break_point_objects())->length(); | 12544 return FixedArray::cast(break_point_objects())->length(); |
12541 } | 12545 } |
12542 #endif // ENABLE_DEBUGGER_SUPPORT | 12546 #endif // ENABLE_DEBUGGER_SUPPORT |
12543 | 12547 |
12544 | 12548 |
12545 } } // namespace v8::internal | 12549 } } // namespace v8::internal |
OLD | NEW |