Line data Source code
1 : // Copyright 2017 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_OBJECTS_SCRIPT_INL_H_
6 : #define V8_OBJECTS_SCRIPT_INL_H_
7 :
8 : #include "src/objects/script.h"
9 :
10 : #include "src/objects/string-inl.h"
11 :
12 : // Has to be the last include (doesn't have include guards):
13 : #include "src/objects/object-macros.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 :
18 : CAST_ACCESSOR(Script)
19 :
20 26283131 : ACCESSORS(Script, source, Object, kSourceOffset)
21 10477616 : ACCESSORS(Script, name, Object, kNameOffset)
22 5107852 : SMI_ACCESSORS(Script, id, kIdOffset)
23 2950895 : SMI_ACCESSORS(Script, line_offset, kLineOffsetOffset)
24 2159967 : SMI_ACCESSORS(Script, column_offset, kColumnOffsetOffset)
25 30470129 : ACCESSORS(Script, context_data, Object, kContextOffset)
26 12952934 : ACCESSORS(Script, wrapper, HeapObject, kWrapperOffset)
27 16605108 : SMI_ACCESSORS(Script, type, kTypeOffset)
28 12469052 : ACCESSORS(Script, line_ends, Object, kLineEndsOffset)
29 15679985 : ACCESSORS_CHECKED(Script, eval_from_shared, Object, kEvalFromSharedOffset,
30 : this->type() != TYPE_WASM)
31 2764453 : SMI_ACCESSORS_CHECKED(Script, eval_from_position, kEvalFromPositionOffset,
32 : this->type() != TYPE_WASM)
33 19606284 : ACCESSORS(Script, shared_function_infos, FixedArray, kSharedFunctionInfosOffset)
34 10979255 : SMI_ACCESSORS(Script, flags, kFlagsOffset)
35 867107 : ACCESSORS(Script, source_url, Object, kSourceUrlOffset)
36 73101 : ACCESSORS(Script, source_mapping_url, Object, kSourceMappingUrlOffset)
37 9598454 : ACCESSORS(Script, host_defined_options, FixedArray, kHostDefinedOptionsOffset)
38 908943 : ACCESSORS_CHECKED(Script, wasm_compiled_module, Object, kEvalFromSharedOffset,
39 : this->type() == TYPE_WASM)
40 :
41 : Script::CompilationType Script::compilation_type() {
42 : return BooleanBit::get(flags(), kCompilationTypeBit) ? COMPILATION_TYPE_EVAL
43 2893500 : : COMPILATION_TYPE_HOST;
44 : }
45 971748 : void Script::set_compilation_type(CompilationType type) {
46 : set_flags(BooleanBit::set(flags(), kCompilationTypeBit,
47 : type == COMPILATION_TYPE_EVAL));
48 971748 : }
49 0 : Script::CompilationState Script::compilation_state() {
50 : return BooleanBit::get(flags(), kCompilationStateBit)
51 : ? COMPILATION_STATE_COMPILED
52 8169 : : COMPILATION_STATE_INITIAL;
53 : }
54 1011250 : void Script::set_compilation_state(CompilationState state) {
55 : set_flags(BooleanBit::set(flags(), kCompilationStateBit,
56 : state == COMPILATION_STATE_COMPILED));
57 1011250 : }
58 : ScriptOriginOptions Script::origin_options() {
59 88062 : return ScriptOriginOptions((flags() & kOriginOptionsMask) >>
60 88062 : kOriginOptionsShift);
61 : }
62 1116891 : void Script::set_origin_options(ScriptOriginOptions origin_options) {
63 : DCHECK(!(origin_options.Flags() & ~((1 << kOriginOptionsSize) - 1)));
64 1116891 : set_flags((flags() & ~kOriginOptionsMask) |
65 1116891 : (origin_options.Flags() << kOriginOptionsShift));
66 1116891 : }
67 :
68 157633 : bool Script::HasValidSource() {
69 : Object* src = this->source();
70 157633 : if (!src->IsString()) return true;
71 : String* src_str = String::cast(src);
72 157633 : if (!StringShape(src_str).IsExternal()) return true;
73 143427 : if (src_str->IsOneByteRepresentation()) {
74 143387 : return ExternalOneByteString::cast(src)->resource() != nullptr;
75 40 : } else if (src_str->IsTwoByteRepresentation()) {
76 40 : return ExternalTwoByteString::cast(src)->resource() != nullptr;
77 : }
78 : return true;
79 : }
80 :
81 : } // namespace internal
82 : } // namespace v8
83 :
84 : #include "src/objects/object-macros-undef.h"
85 :
86 : #endif // V8_OBJECTS_SCRIPT_INL_H_
|