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