OLD | NEW |
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 int literalTypeFlag = object_literal->EncodeLiteralType(); |
31 result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS)); | 31 DCHECK_NE(kArrayLiteralFlag, literalTypeFlag); |
32 } else { | 32 result->set(kLiteralTypeSlot, Smi::FromInt(literalTypeFlag)); |
33 result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS)); | |
34 } | |
35 result->set(kElementsSlot, *object_literal->constant_properties()); | 33 result->set(kElementsSlot, *object_literal->constant_properties()); |
36 } else { | 34 } else { |
37 ArrayLiteral* array_literal = expression->AsArrayLiteral(); | 35 ArrayLiteral* array_literal = expression->AsArrayLiteral(); |
38 DCHECK(array_literal != NULL && array_literal->is_simple()); | 36 DCHECK(array_literal != NULL && array_literal->is_simple()); |
39 result->set(kLiteralTypeSlot, Smi::FromInt(ARRAY_LITERAL)); | 37 result->set(kLiteralTypeSlot, Smi::FromInt(kArrayLiteralFlag)); |
40 result->set(kElementsSlot, *array_literal->constant_elements()); | 38 result->set(kElementsSlot, *array_literal->constant_elements()); |
41 } | 39 } |
42 return result; | 40 return result; |
43 } | 41 } |
44 | 42 |
45 CompileTimeValue::LiteralType CompileTimeValue::GetLiteralType( | 43 int CompileTimeValue::GetLiteralTypeFlags(Handle<FixedArray> value) { |
46 Handle<FixedArray> value) { | 44 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 } | 45 } |
50 | 46 |
51 Handle<HeapObject> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 47 Handle<HeapObject> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
52 return Handle<HeapObject>(HeapObject::cast(value->get(kElementsSlot))); | 48 return Handle<HeapObject>(HeapObject::cast(value->get(kElementsSlot))); |
53 } | 49 } |
54 | 50 |
55 } // namespace internal | 51 } // namespace internal |
56 } // namespace v8 | 52 } // namespace v8 |
OLD | NEW |