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

Side by Side Diff: src/ast/compile-time-value.cc

Issue 2445333002: Ensure slow properties for simple {__proto__:null} literals. (Closed)
Patch Set: minor cleanup Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast/compile-time-value.h" 5 #include "src/ast/compile-time-value.h"
6 6
7 #include "src/ast/ast.h" 7 #include "src/ast/ast.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/handles-inl.h" 9 #include "src/handles-inl.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
11 #include "src/objects-inl.h" 11 #include "src/objects-inl.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 16 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
17 if (expression->IsLiteral()) return true; 17 if (expression->IsLiteral()) return true;
18 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); 18 MaterializedLiteral* lit = expression->AsMaterializedLiteral();
19 return lit != NULL && lit->is_simple(); 19 return lit != NULL && lit->is_simple();
20 } 20 }
21 21
22 Handle<FixedArray> CompileTimeValue::GetValue(Isolate* isolate, 22 Handle<FixedArray> CompileTimeValue::GetValue(Isolate* isolate,
23 Expression* expression) { 23 Expression* expression) {
24 Factory* factory = isolate->factory(); 24 Factory* factory = isolate->factory();
25 DCHECK(IsCompileTimeValue(expression)); 25 DCHECK(IsCompileTimeValue(expression));
26 Handle<FixedArray> result = factory->NewFixedArray(2, TENURED); 26 Handle<FixedArray> result = factory->NewFixedArray(2, TENURED);
27 ObjectLiteral* object_literal = expression->AsObjectLiteral(); 27 if (expression->IsObjectLiteral()) {
28 if (object_literal != NULL) { 28 ObjectLiteral* object_literal = expression->AsObjectLiteral();
29 DCHECK(object_literal->is_simple()); 29 DCHECK(object_literal->is_simple());
30 if (object_literal->fast_elements()) { 30 result->set(kLiteralTypeSlot,
31 result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS)); 31 Smi::FromInt(object_literal->EncodeLiteralType()));
32 } else {
33 result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS));
34 }
35 result->set(kElementsSlot, *object_literal->constant_properties()); 32 result->set(kElementsSlot, *object_literal->constant_properties());
36 } else { 33 } else {
37 ArrayLiteral* array_literal = expression->AsArrayLiteral(); 34 ArrayLiteral* array_literal = expression->AsArrayLiteral();
38 DCHECK(array_literal != NULL && array_literal->is_simple()); 35 DCHECK(array_literal != NULL && array_literal->is_simple());
39 result->set(kLiteralTypeSlot, Smi::FromInt(ARRAY_LITERAL)); 36 result->set(kLiteralTypeSlot, Smi::FromInt(kArrayLiteralFlag));
40 result->set(kElementsSlot, *array_literal->constant_elements()); 37 result->set(kElementsSlot, *array_literal->constant_elements());
41 } 38 }
42 return result; 39 return result;
43 } 40 }
44 41
45 CompileTimeValue::LiteralType CompileTimeValue::GetLiteralType( 42 int CompileTimeValue::GetLiteralTypeFlags(Handle<FixedArray> value) {
46 Handle<FixedArray> value) { 43 return Smi::cast(value->get(kLiteralTypeSlot))->value();
47 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot));
48 return static_cast<LiteralType>(literal_type->value());
49 } 44 }
50 45
51 Handle<HeapObject> CompileTimeValue::GetElements(Handle<FixedArray> value) { 46 Handle<HeapObject> CompileTimeValue::GetElements(Handle<FixedArray> value) {
52 return Handle<HeapObject>(HeapObject::cast(value->get(kElementsSlot))); 47 return Handle<HeapObject>(HeapObject::cast(value->get(kElementsSlot)));
53 } 48 }
54 49
55 } // namespace internal 50 } // namespace internal
56 } // namespace v8 51 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698