• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "src/interpreter/bytecode-flags.h"
6 
7 #include "src/ast/ast-value-factory.h"
8 #include "src/ast/ast.h"
9 #include "src/builtins/builtins-constructor.h"
10 #include "src/code-stubs.h"
11 #include "src/objects-inl.h"
12 
13 namespace v8 {
14 namespace internal {
15 namespace interpreter {
16 
17 // static
Encode(bool use_fast_shallow_clone,int runtime_flags)18 uint8_t CreateArrayLiteralFlags::Encode(bool use_fast_shallow_clone,
19                                         int runtime_flags) {
20   uint8_t result = FlagsBits::encode(runtime_flags);
21   result |= FastCloneSupportedBit::encode(use_fast_shallow_clone);
22   return result;
23 }
24 
25 // static
Encode(int runtime_flags,bool fast_clone_supported)26 uint8_t CreateObjectLiteralFlags::Encode(int runtime_flags,
27                                          bool fast_clone_supported) {
28   uint8_t result = FlagsBits::encode(runtime_flags);
29   result |= FastCloneSupportedBit::encode(fast_clone_supported);
30   return result;
31 }
32 
33 // static
Encode(bool pretenure,bool is_function_scope)34 uint8_t CreateClosureFlags::Encode(bool pretenure, bool is_function_scope) {
35   uint8_t result = PretenuredBit::encode(pretenure);
36   if (!FLAG_always_opt && !FLAG_prepare_always_opt &&
37       pretenure == NOT_TENURED && is_function_scope) {
38     result |= FastNewClosureBit::encode(true);
39   }
40   return result;
41 }
42 
43 // static
GetFlagForLiteral(const AstStringConstants * ast_constants,Literal * literal)44 TestTypeOfFlags::LiteralFlag TestTypeOfFlags::GetFlagForLiteral(
45     const AstStringConstants* ast_constants, Literal* literal) {
46   const AstRawString* raw_literal = literal->AsRawString();
47   if (raw_literal == ast_constants->number_string()) {
48     return LiteralFlag::kNumber;
49   } else if (raw_literal == ast_constants->string_string()) {
50     return LiteralFlag::kString;
51   } else if (raw_literal == ast_constants->symbol_string()) {
52     return LiteralFlag::kSymbol;
53   } else if (raw_literal == ast_constants->boolean_string()) {
54     return LiteralFlag::kBoolean;
55   } else if (raw_literal == ast_constants->bigint_string()) {
56     return LiteralFlag::kBigInt;
57   } else if (raw_literal == ast_constants->undefined_string()) {
58     return LiteralFlag::kUndefined;
59   } else if (raw_literal == ast_constants->function_string()) {
60     return LiteralFlag::kFunction;
61   } else if (raw_literal == ast_constants->object_string()) {
62     return LiteralFlag::kObject;
63   } else {
64     return LiteralFlag::kOther;
65   }
66 }
67 
68 // static
Encode(LiteralFlag literal_flag)69 uint8_t TestTypeOfFlags::Encode(LiteralFlag literal_flag) {
70   return static_cast<uint8_t>(literal_flag);
71 }
72 
73 // static
Decode(uint8_t raw_flag)74 TestTypeOfFlags::LiteralFlag TestTypeOfFlags::Decode(uint8_t raw_flag) {
75   DCHECK_LE(raw_flag, static_cast<uint8_t>(LiteralFlag::kOther));
76   return static_cast<LiteralFlag>(raw_flag);
77 }
78 
79 // static
Encode(LanguageMode language_mode,LookupHoistingMode lookup_hoisting_mode)80 uint8_t StoreLookupSlotFlags::Encode(LanguageMode language_mode,
81                                      LookupHoistingMode lookup_hoisting_mode) {
82   DCHECK_IMPLIES(lookup_hoisting_mode == LookupHoistingMode::kLegacySloppy,
83                  language_mode == LanguageMode::kSloppy);
84   return LanguageModeBit::encode(language_mode) |
85          LookupHoistingModeBit::encode(static_cast<bool>(lookup_hoisting_mode));
86 }
87 
88 }  // namespace interpreter
89 }  // namespace internal
90 }  // namespace v8
91