Commit 50af6171 authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

[torque] Improve field types in Script

This is a partial reland of https://crrev.com/c/v8/v8/+/2199640 .

Change-Id: I9e7506ade0938079166e63926e11b67615f909e7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2216239Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#68083}
parent 2fbef5ec
......@@ -17,29 +17,16 @@
namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(Script, Struct)
TQ_OBJECT_CONSTRUCTORS_IMPL(Script)
NEVER_READ_ONLY_SPACE_IMPL(Script)
CAST_ACCESSOR(Script)
ACCESSORS(Script, source, Object, kSourceOffset)
ACCESSORS(Script, name, Object, kNameOffset)
SMI_ACCESSORS(Script, id, kIdOffset)
SMI_ACCESSORS(Script, line_offset, kLineOffsetOffset)
SMI_ACCESSORS(Script, column_offset, kColumnOffsetOffset)
ACCESSORS(Script, context_data, Object, kContextOffset)
SMI_ACCESSORS(Script, type, kScriptTypeOffset)
ACCESSORS(Script, line_ends, Object, kLineEndsOffset)
ACCESSORS_CHECKED(Script, eval_from_shared_or_wrapped_arguments, Object,
kEvalFromSharedOrWrappedArgumentsOffset,
this->type() != TYPE_WASM)
SMI_ACCESSORS_CHECKED(Script, eval_from_position, kEvalFromPositionOffset,
this->type() != TYPE_WASM)
SMI_ACCESSORS(Script, flags, kFlagsOffset)
ACCESSORS(Script, source_url, Object, kSourceUrlOffset)
ACCESSORS(Script, source_mapping_url, Object, kSourceMappingUrlOffset)
ACCESSORS(Script, host_defined_options, FixedArray, kHostDefinedOptionsOffset)
ACCESSORS_CHECKED(Script, wasm_breakpoint_infos, FixedArray,
kEvalFromSharedOrWrappedArgumentsOffset,
this->type() == TYPE_WASM)
......@@ -100,39 +87,30 @@ wasm::NativeModule* Script::wasm_native_module() const {
}
Script::CompilationType Script::compilation_type() {
return BooleanBit::get(flags(), kCompilationTypeBit) ? COMPILATION_TYPE_EVAL
: COMPILATION_TYPE_HOST;
return CompilationTypeBit::decode(flags());
}
void Script::set_compilation_type(CompilationType type) {
set_flags(BooleanBit::set(flags(), kCompilationTypeBit,
type == COMPILATION_TYPE_EVAL));
set_flags(CompilationTypeBit::update(flags(), type));
}
Script::CompilationState Script::compilation_state() {
return BooleanBit::get(flags(), kCompilationStateBit)
? COMPILATION_STATE_COMPILED
: COMPILATION_STATE_INITIAL;
return CompilationStateBit::decode(flags());
}
void Script::set_compilation_state(CompilationState state) {
set_flags(BooleanBit::set(flags(), kCompilationStateBit,
state == COMPILATION_STATE_COMPILED));
set_flags(CompilationStateBit::update(flags(), state));
}
bool Script::is_repl_mode() const {
return BooleanBit::get(flags(), kREPLModeBit);
}
bool Script::is_repl_mode() const { return IsReplModeBit::decode(flags()); }
void Script::set_is_repl_mode(bool value) {
set_flags(BooleanBit::set(flags(), kREPLModeBit, value));
set_flags(IsReplModeBit::update(flags(), value));
}
ScriptOriginOptions Script::origin_options() {
return ScriptOriginOptions((flags() & kOriginOptionsMask) >>
kOriginOptionsShift);
return ScriptOriginOptions(OriginOptionsBits::decode(flags()));
}
void Script::set_origin_options(ScriptOriginOptions origin_options) {
DCHECK(!(origin_options.Flags() & ~((1 << kOriginOptionsSize) - 1)));
set_flags((flags() & ~kOriginOptionsMask) |
(origin_options.Flags() << kOriginOptionsShift));
DCHECK(!(origin_options.Flags() & ~((1 << OriginOptionsBits::kSize) - 1)));
set_flags(OriginOptionsBits::update(flags(), origin_options.Flags()));
}
bool Script::HasValidSource() {
......
......@@ -11,6 +11,7 @@
#include "src/objects/fixed-array.h"
#include "src/objects/objects.h"
#include "src/objects/struct.h"
#include "torque-generated/bit-fields-tq.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
......@@ -20,7 +21,7 @@ namespace v8 {
namespace internal {
// Script describes a script which has been added to the VM.
class Script : public Struct {
class Script : public TorqueGeneratedScript<Script, Struct> {
public:
// Script ID used for temporary scripts, which shouldn't be added to the
// script list.
......@@ -45,31 +46,9 @@ class Script : public Struct {
COMPILATION_STATE_COMPILED = 1
};
// [source]: the script source.
DECL_ACCESSORS(source, Object)
// [name]: the script name.
DECL_ACCESSORS(name, Object)
// [id]: the script id.
DECL_INT_ACCESSORS(id)
// [line_offset]: script line offset in resource from where it was extracted.
DECL_INT_ACCESSORS(line_offset)
// [column_offset]: script column offset in resource from where it was
// extracted.
DECL_INT_ACCESSORS(column_offset)
// [context_data]: context data for the context this script was compiled in.
DECL_ACCESSORS(context_data, Object)
// [type]: the script type.
DECL_INT_ACCESSORS(type)
// [line_ends]: FixedArray of line ends positions.
DECL_ACCESSORS(line_ends, Object)
DECL_ACCESSORS(eval_from_shared_or_wrapped_arguments, Object)
// [eval_from_shared]: for eval scripts the shared function info for the
......@@ -95,15 +74,6 @@ class Script : public Struct {
// function infos created from this script.
DECL_ACCESSORS(shared_function_infos, WeakFixedArray)
// [flags]: Holds an exciting bitfield.
DECL_INT_ACCESSORS(flags)
// [source_url]: sourceURL from magic comment
DECL_ACCESSORS(source_url, Object)
// [source_mapping_url]: sourceMappingURL magic comment
DECL_ACCESSORS(source_mapping_url, Object)
// [wasm_breakpoint_infos]: the list of {BreakPointInfo} objects describing
// all WebAssembly breakpoints for modules/instances managed via this script.
// This must only be called if the type of this script is TYPE_WASM.
......@@ -120,9 +90,6 @@ class Script : public Struct {
// This must only be called if the type of this script is TYPE_WASM.
DECL_ACCESSORS(wasm_weak_instance_list, WeakArrayList)
// [host_defined_options]: Options defined by the embedder.
DECL_ACCESSORS(host_defined_options, FixedArray)
// [compilation_type]: how the the script was compiled. Encoded in the
// 'flags' field.
inline CompilationType compilation_type();
......@@ -144,8 +111,6 @@ class Script : public Struct {
inline v8::ScriptOriginOptions origin_options();
inline void set_origin_options(ScriptOriginOptions origin_options);
DECL_CAST(Script)
// If script source is an external string, check that the underlying
// resource is accessible. Otherwise, always return true.
inline bool HasValidSource();
......@@ -218,20 +183,11 @@ class Script : public Struct {
DECL_PRINTER(Script)
DECL_VERIFIER(Script)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
TORQUE_GENERATED_SCRIPT_FIELDS)
private:
// Bit positions in the flags field.
static const int kCompilationTypeBit = 0;
static const int kCompilationStateBit = 1;
static const int kREPLModeBit = 2;
static const int kOriginOptionsShift = 3;
static const int kOriginOptionsSize = 4;
static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1)
<< kOriginOptionsShift;
OBJECT_CONSTRUCTORS(Script, Struct);
DEFINE_TORQUE_GENERATED_SCRIPT_FLAGS()
TQ_OBJECT_CONSTRUCTORS(Script)
};
} // namespace internal
......
......@@ -2,20 +2,56 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
type CompilationType extends int32 constexpr 'Script::CompilationType';
type CompilationState extends int32 constexpr 'Script::CompilationState';
bitfield struct ScriptFlags extends uint31 {
compilation_type: CompilationType: 1 bit;
compilation_state: CompilationState: 1 bit;
is_repl_mode: bool: 1 bit;
origin_options: int32: 4 bit;
}
@generateCppClass
extern class Script extends Struct {
source: Object;
// [source]: the script source.
source: String|Undefined;
// [name]: the script name.
name: Object;
// [line_offset]: script line offset in resource from where it was extracted.
line_offset: Smi;
// [column_offset]: script column offset in resource from where it was
// extracted.
column_offset: Smi;
context: Object;
// [context_data]: context data for the context this script was compiled in.
context_data: Smi|Undefined|Symbol;
script_type: Smi;
line_ends: Object;
// [line_ends]: FixedArray of line ends positions.
line_ends: FixedArray|Undefined;
// [id]: the script id.
id: Smi;
eval_from_shared_or_wrapped_arguments: Object;
eval_from_shared_or_wrapped_arguments: SharedFunctionInfo|FixedArray|
Undefined;
eval_from_position: Smi|Foreign; // Smi or Managed<wasm::NativeModule>
shared_function_infos: Object;
flags: Smi;
source_url: Object;
shared_function_infos: WeakFixedArray|WeakArrayList;
// [flags]: Holds an exciting bitfield.
flags: SmiTagged<ScriptFlags>;
// [source_url]: sourceURL from magic comment
source_url: String|Undefined;
// [source_mapping_url]: sourceMappingURL magic comment
source_mapping_url: Object;
host_defined_options: Object;
// [host_defined_options]: Options defined by the embedder.
host_defined_options: FixedArray;
}
......@@ -1129,7 +1129,7 @@ void V8HeapExplorer::ExtractScriptReferences(HeapEntry* entry, Script script) {
SetInternalReference(entry, "source", script.source(), Script::kSourceOffset);
SetInternalReference(entry, "name", script.name(), Script::kNameOffset);
SetInternalReference(entry, "context_data", script.context_data(),
Script::kContextOffset);
Script::kContextDataOffset);
TagObject(script.line_ends(), "(script line ends)");
SetInternalReference(entry, "line_ends", script.line_ends(),
Script::kLineEndsOffset);
......
......@@ -540,7 +540,7 @@ void Serializer::ObjectSerializer::Serialize() {
if (object_.IsScript()) {
// Clear cached line ends.
Object undefined = ReadOnlyRoots(serializer_->isolate()).undefined_value();
Oddball undefined = ReadOnlyRoots(serializer_->isolate()).undefined_value();
Script::cast(object_).set_line_ends(undefined);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment