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

Unified Diff: src/objects.cc

Issue 6286043: Direct call to eval passes strict mode through. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Extra argument to Resolve*Eval* Created 9 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 36a8e5c2aabc360e74cb58a40acd35fb6f4ed151..1979d80e2ad49861bdb9ebb793f6e2c025bc062b 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -7982,20 +7982,23 @@ class StringKey : public HashTableKey {
// StringSharedKeys are used as keys in the eval cache.
class StringSharedKey : public HashTableKey {
public:
- StringSharedKey(String* source, SharedFunctionInfo* shared)
- : source_(source), shared_(shared) { }
+ StringSharedKey(String* source, SharedFunctionInfo* shared, bool strict)
+ : source_(source), shared_(shared), strict_(strict) { }
bool IsMatch(Object* other) {
if (!other->IsFixedArray()) return false;
FixedArray* pair = FixedArray::cast(other);
SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0));
if (shared != shared_) return false;
+ bool strict = Smi::cast(pair->get(2))->value() != 0;
Lasse Reichstein 2011/02/03 12:36:01 Do you need to store the strictness in a separate
Martin Maly 2011/02/04 01:02:34 I believe I do need to store the strict flag. The
+ if (strict != strict_) return false;
String* source = String::cast(pair->get(1));
return source->Equals(source_);
}
static uint32_t StringSharedHashHelper(String* source,
- SharedFunctionInfo* shared) {
+ SharedFunctionInfo* shared,
+ bool strict) {
uint32_t hash = source->Hash();
if (shared->HasSourceCode()) {
// Instead of using the SharedFunctionInfo pointer in the hash
@@ -8005,36 +8008,40 @@ class StringSharedKey : public HashTableKey {
// collection.
Script* script = Script::cast(shared->script());
hash ^= String::cast(script->source())->Hash();
+ hash ^= strict ? 0x8000 : 0x800;
Martin Maly 2011/02/02 23:56:22 Just a guess, there may be better (or more V8 code
Lasse Reichstein 2011/02/03 12:36:01 I don't think it matters what you do for strict-mo
Martin Maly 2011/02/04 01:02:34 Done.
hash += shared->start_position();
}
return hash;
}
uint32_t Hash() {
- return StringSharedHashHelper(source_, shared_);
+ return StringSharedHashHelper(source_, shared_, strict_);
}
uint32_t HashForObject(Object* obj) {
FixedArray* pair = FixedArray::cast(obj);
SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0));
String* source = String::cast(pair->get(1));
- return StringSharedHashHelper(source, shared);
+ bool strict = Smi::cast(pair->get(2))->value() != 0;
+ return StringSharedHashHelper(source, shared, strict);
}
MUST_USE_RESULT MaybeObject* AsObject() {
Object* obj;
- { MaybeObject* maybe_obj = Heap::AllocateFixedArray(2);
+ { MaybeObject* maybe_obj = Heap::AllocateFixedArray(3);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
FixedArray* pair = FixedArray::cast(obj);
pair->set(0, shared_);
pair->set(1, source_);
+ pair->set(2, Smi::FromInt(strict_ ? 1 : 0));
return pair;
}
private:
String* source_;
SharedFunctionInfo* shared_;
+ bool strict_;
};
@@ -8993,8 +9000,10 @@ Object* CompilationCacheTable::Lookup(String* src) {
}
-Object* CompilationCacheTable::LookupEval(String* src, Context* context) {
- StringSharedKey key(src, context->closure()->shared());
+Object* CompilationCacheTable::LookupEval(String* src,
+ Context* context,
+ bool is_strict) {
+ StringSharedKey key(src, context->closure()->shared(), is_strict);
Martin Maly 2011/02/02 23:56:22 It seems weird that this function hashes by: conte
Lasse Reichstein 2011/02/03 12:36:01 I'm not sure I understand the question. You can ha
Martin Maly 2011/02/04 01:02:34 Makes sense, thanks for the explanation.
int entry = FindEntry(&key);
if (entry == kNotFound) return Heap::undefined_value();
return get(EntryToIndex(entry) + 1);
@@ -9029,8 +9038,10 @@ MaybeObject* CompilationCacheTable::Put(String* src, Object* value) {
MaybeObject* CompilationCacheTable::PutEval(String* src,
Context* context,
- Object* value) {
- StringSharedKey key(src, context->closure()->shared());
+ SharedFunctionInfo* value) {
+ StringSharedKey key(src,
+ context->closure()->shared(),
+ value->strict_mode());
Object* obj;
{ MaybeObject* maybe_obj = EnsureCapacity(1, &key);
if (!maybe_obj->ToObject(&obj)) return maybe_obj;

Powered by Google App Engine
This is Rietveld 408576698