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

Side by Side Diff: src/objects.cc

Issue 8417035: Introduce extended mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments. Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 7245 matching lines...) Expand 10 before | Expand all | Expand 10 after
7256 } else { 7256 } else {
7257 map()->set_non_instance_prototype(false); 7257 map()->set_non_instance_prototype(false);
7258 } 7258 }
7259 7259
7260 return SetInstancePrototype(construct_prototype); 7260 return SetInstancePrototype(construct_prototype);
7261 } 7261 }
7262 7262
7263 7263
7264 Object* JSFunction::RemovePrototype() { 7264 Object* JSFunction::RemovePrototype() {
7265 Context* global_context = context()->global_context(); 7265 Context* global_context = context()->global_context();
7266 Map* no_prototype_map = shared()->strict_mode() 7266 Map* no_prototype_map = shared()->is_classic_mode()
7267 ? global_context->strict_mode_function_without_prototype_map() 7267 ? global_context->function_without_prototype_map()
7268 : global_context->function_without_prototype_map(); 7268 : global_context->strict_mode_function_without_prototype_map();
7269 7269
7270 if (map() == no_prototype_map) { 7270 if (map() == no_prototype_map) {
7271 // Be idempotent. 7271 // Be idempotent.
7272 return this; 7272 return this;
7273 } 7273 }
7274 7274
7275 ASSERT(!shared()->strict_mode() || 7275 ASSERT(shared()->is_classic_mode() ||
7276 map() == global_context->strict_mode_function_map()); 7276 map() == global_context->strict_mode_function_map());
7277 ASSERT(shared()->strict_mode() || map() == global_context->function_map()); 7277 ASSERT(!shared()->is_classic_mode() ||
7278 map() == global_context->function_map());
rossberg 2011/11/09 12:15:29 Nit: These two assertions could be a single map()
7278 7279
7279 set_map(no_prototype_map); 7280 set_map(no_prototype_map);
7280 set_prototype_or_initial_map(no_prototype_map->GetHeap()->the_hole_value()); 7281 set_prototype_or_initial_map(no_prototype_map->GetHeap()->the_hole_value());
7281 return this; 7282 return this;
7282 } 7283 }
7283 7284
7284 7285
7285 Object* JSFunction::SetInstanceClassName(String* name) { 7286 Object* JSFunction::SetInstanceClassName(String* name) {
7286 shared()->set_instance_class_name(name); 7287 shared()->set_instance_class_name(name);
7287 return this; 7288 return this;
(...skipping 3207 matching lines...) Expand 10 before | Expand all | Expand 10 after
10495 String* string_; 10496 String* string_;
10496 uint32_t hash_; 10497 uint32_t hash_;
10497 }; 10498 };
10498 10499
10499 10500
10500 // StringSharedKeys are used as keys in the eval cache. 10501 // StringSharedKeys are used as keys in the eval cache.
10501 class StringSharedKey : public HashTableKey { 10502 class StringSharedKey : public HashTableKey {
10502 public: 10503 public:
10503 StringSharedKey(String* source, 10504 StringSharedKey(String* source,
10504 SharedFunctionInfo* shared, 10505 SharedFunctionInfo* shared,
10505 StrictModeFlag strict_mode) 10506 LanguageMode language_mode)
10506 : source_(source), 10507 : source_(source),
10507 shared_(shared), 10508 shared_(shared),
10508 strict_mode_(strict_mode) { } 10509 language_mode_(language_mode) { }
10509 10510
10510 bool IsMatch(Object* other) { 10511 bool IsMatch(Object* other) {
10511 if (!other->IsFixedArray()) return false; 10512 if (!other->IsFixedArray()) return false;
10512 FixedArray* pair = FixedArray::cast(other); 10513 FixedArray* pair = FixedArray::cast(other);
10513 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); 10514 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0));
10514 if (shared != shared_) return false; 10515 if (shared != shared_) return false;
10515 int strict_unchecked = Smi::cast(pair->get(2))->value(); 10516 int language_unchecked = Smi::cast(pair->get(2))->value();
10516 ASSERT(strict_unchecked == kStrictMode || 10517 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked);
10517 strict_unchecked == kNonStrictMode); 10518 if (language_mode != language_mode_) return false;
10518 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked);
10519 if (strict_mode != strict_mode_) return false;
10520 String* source = String::cast(pair->get(1)); 10519 String* source = String::cast(pair->get(1));
10521 return source->Equals(source_); 10520 return source->Equals(source_);
10522 } 10521 }
10523 10522
10524 static uint32_t StringSharedHashHelper(String* source, 10523 static uint32_t StringSharedHashHelper(String* source,
10525 SharedFunctionInfo* shared, 10524 SharedFunctionInfo* shared,
10526 StrictModeFlag strict_mode) { 10525 LanguageMode language_mode) {
10527 uint32_t hash = source->Hash(); 10526 uint32_t hash = source->Hash();
10528 if (shared->HasSourceCode()) { 10527 if (shared->HasSourceCode()) {
10529 // Instead of using the SharedFunctionInfo pointer in the hash 10528 // Instead of using the SharedFunctionInfo pointer in the hash
10530 // code computation, we use a combination of the hash of the 10529 // code computation, we use a combination of the hash of the
10531 // script source code and the start and end positions. We do 10530 // script source code and the start and end positions. We do
10532 // this to ensure that the cache entries can survive garbage 10531 // this to ensure that the cache entries can survive garbage
10533 // collection. 10532 // collection.
10534 Script* script = Script::cast(shared->script()); 10533 Script* script = Script::cast(shared->script());
10535 hash ^= String::cast(script->source())->Hash(); 10534 hash ^= String::cast(script->source())->Hash();
10536 if (strict_mode == kStrictMode) hash ^= 0x8000; 10535 if (language_mode == STRICT_MODE) hash ^= 0x8000;
10536 if (language_mode == EXTENDED_MODE) hash ^= 0x0080;
10537 hash += shared->start_position(); 10537 hash += shared->start_position();
10538 } 10538 }
10539 return hash; 10539 return hash;
10540 } 10540 }
10541 10541
10542 uint32_t Hash() { 10542 uint32_t Hash() {
10543 return StringSharedHashHelper(source_, shared_, strict_mode_); 10543 return StringSharedHashHelper(source_, shared_, language_mode_);
10544 } 10544 }
10545 10545
10546 uint32_t HashForObject(Object* obj) { 10546 uint32_t HashForObject(Object* obj) {
10547 FixedArray* pair = FixedArray::cast(obj); 10547 FixedArray* pair = FixedArray::cast(obj);
10548 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); 10548 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0));
10549 String* source = String::cast(pair->get(1)); 10549 String* source = String::cast(pair->get(1));
10550 int strict_unchecked = Smi::cast(pair->get(2))->value(); 10550 int language_unchecked = Smi::cast(pair->get(2))->value();
10551 ASSERT(strict_unchecked == kStrictMode || 10551 ASSERT(language_unchecked == CLASSIC_MODE ||
10552 strict_unchecked == kNonStrictMode); 10552 language_unchecked == STRICT_MODE ||
10553 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); 10553 language_unchecked == EXTENDED_MODE);
10554 return StringSharedHashHelper(source, shared, strict_mode); 10554 LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked);
10555 return StringSharedHashHelper(source, shared, language_mode);
10555 } 10556 }
10556 10557
10557 MUST_USE_RESULT MaybeObject* AsObject() { 10558 MUST_USE_RESULT MaybeObject* AsObject() {
10558 Object* obj; 10559 Object* obj;
10559 { MaybeObject* maybe_obj = source_->GetHeap()->AllocateFixedArray(3); 10560 { MaybeObject* maybe_obj = source_->GetHeap()->AllocateFixedArray(3);
10560 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 10561 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
10561 } 10562 }
10562 FixedArray* pair = FixedArray::cast(obj); 10563 FixedArray* pair = FixedArray::cast(obj);
10563 pair->set(0, shared_); 10564 pair->set(0, shared_);
10564 pair->set(1, source_); 10565 pair->set(1, source_);
10565 pair->set(2, Smi::FromInt(strict_mode_)); 10566 pair->set(2, Smi::FromInt(language_mode_));
10566 return pair; 10567 return pair;
10567 } 10568 }
10568 10569
10569 private: 10570 private:
10570 String* source_; 10571 String* source_;
10571 SharedFunctionInfo* shared_; 10572 SharedFunctionInfo* shared_;
10572 StrictModeFlag strict_mode_; 10573 LanguageMode language_mode_;
10573 }; 10574 };
10574 10575
10575 10576
10576 // RegExpKey carries the source and flags of a regular expression as key. 10577 // RegExpKey carries the source and flags of a regular expression as key.
10577 class RegExpKey : public HashTableKey { 10578 class RegExpKey : public HashTableKey {
10578 public: 10579 public:
10579 RegExpKey(String* string, JSRegExp::Flags flags) 10580 RegExpKey(String* string, JSRegExp::Flags flags)
10580 : string_(string), 10581 : string_(string),
10581 flags_(Smi::FromInt(flags.value())) { } 10582 flags_(Smi::FromInt(flags.value())) { }
10582 10583
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
11717 Object* CompilationCacheTable::Lookup(String* src) { 11718 Object* CompilationCacheTable::Lookup(String* src) {
11718 StringKey key(src); 11719 StringKey key(src);
11719 int entry = FindEntry(&key); 11720 int entry = FindEntry(&key);
11720 if (entry == kNotFound) return GetHeap()->undefined_value(); 11721 if (entry == kNotFound) return GetHeap()->undefined_value();
11721 return get(EntryToIndex(entry) + 1); 11722 return get(EntryToIndex(entry) + 1);
11722 } 11723 }
11723 11724
11724 11725
11725 Object* CompilationCacheTable::LookupEval(String* src, 11726 Object* CompilationCacheTable::LookupEval(String* src,
11726 Context* context, 11727 Context* context,
11727 StrictModeFlag strict_mode) { 11728 LanguageMode language_mode) {
11728 StringSharedKey key(src, context->closure()->shared(), strict_mode); 11729 StringSharedKey key(src, context->closure()->shared(), language_mode);
11729 int entry = FindEntry(&key); 11730 int entry = FindEntry(&key);
11730 if (entry == kNotFound) return GetHeap()->undefined_value(); 11731 if (entry == kNotFound) return GetHeap()->undefined_value();
11731 return get(EntryToIndex(entry) + 1); 11732 return get(EntryToIndex(entry) + 1);
11732 } 11733 }
11733 11734
11734 11735
11735 Object* CompilationCacheTable::LookupRegExp(String* src, 11736 Object* CompilationCacheTable::LookupRegExp(String* src,
11736 JSRegExp::Flags flags) { 11737 JSRegExp::Flags flags) {
11737 RegExpKey key(src, flags); 11738 RegExpKey key(src, flags);
11738 int entry = FindEntry(&key); 11739 int entry = FindEntry(&key);
(...skipping 17 matching lines...) Expand all
11756 cache->ElementAdded(); 11757 cache->ElementAdded();
11757 return cache; 11758 return cache;
11758 } 11759 }
11759 11760
11760 11761
11761 MaybeObject* CompilationCacheTable::PutEval(String* src, 11762 MaybeObject* CompilationCacheTable::PutEval(String* src,
11762 Context* context, 11763 Context* context,
11763 SharedFunctionInfo* value) { 11764 SharedFunctionInfo* value) {
11764 StringSharedKey key(src, 11765 StringSharedKey key(src,
11765 context->closure()->shared(), 11766 context->closure()->shared(),
11766 value->strict_mode_flag()); 11767 value->language_mode());
11767 Object* obj; 11768 Object* obj;
11768 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); 11769 { MaybeObject* maybe_obj = EnsureCapacity(1, &key);
11769 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 11770 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
11770 } 11771 }
11771 11772
11772 CompilationCacheTable* cache = 11773 CompilationCacheTable* cache =
11773 reinterpret_cast<CompilationCacheTable*>(obj); 11774 reinterpret_cast<CompilationCacheTable*>(obj);
11774 int entry = cache->FindInsertionEntry(key.Hash()); 11775 int entry = cache->FindInsertionEntry(key.Hash());
11775 11776
11776 Object* k; 11777 Object* k;
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
12750 if (break_point_objects()->IsUndefined()) return 0; 12751 if (break_point_objects()->IsUndefined()) return 0;
12751 // Single break point. 12752 // Single break point.
12752 if (!break_point_objects()->IsFixedArray()) return 1; 12753 if (!break_point_objects()->IsFixedArray()) return 1;
12753 // Multiple break points. 12754 // Multiple break points.
12754 return FixedArray::cast(break_point_objects())->length(); 12755 return FixedArray::cast(break_point_objects())->length();
12755 } 12756 }
12756 #endif // ENABLE_DEBUGGER_SUPPORT 12757 #endif // ENABLE_DEBUGGER_SUPPORT
12757 12758
12758 12759
12759 } } // namespace v8::internal 12760 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | test/mjsunit/harmony/debug-blockscopes.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698