1 // Copyright 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_AST_COMPILE_TIME_VALUE 6 #define V8_AST_COMPILE_TIME_VALUE 7 8 #include "src/allocation.h" 9 #include "src/globals.h" 10 11 namespace v8 { 12 namespace internal { 13 14 class Expression; 15 16 // Support for handling complex values (array and object literals) that 17 // can be fully handled at compile time. 18 class CompileTimeValue : public AllStatic { 19 public: 20 enum LiteralType { 21 OBJECT_LITERAL_FAST_ELEMENTS, 22 OBJECT_LITERAL_SLOW_ELEMENTS, 23 ARRAY_LITERAL 24 }; 25 26 static bool IsCompileTimeValue(Expression* expression); 27 28 // Get the value as a compile time value. 29 static Handle<FixedArray> GetValue(Isolate* isolate, Expression* expression); 30 31 // Get the type of a compile time value returned by GetValue(). 32 static LiteralType GetLiteralType(Handle<FixedArray> value); 33 34 // Get the elements of a compile time value returned by GetValue(). 35 static Handle<HeapObject> GetElements(Handle<FixedArray> value); 36 37 private: 38 static const int kLiteralTypeSlot = 0; 39 static const int kElementsSlot = 1; 40 }; 41 42 } // namespace internal 43 } // namespace v8 44 45 #endif // V8_AST_COMPILE_TIME_VALUE 46