Commit 75c11b86 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[runtime] Derive is_eval from Script::CompilationType in DeclareGlobals

Change-Id: I34aff1cef476a1237e59e8151b82bdb09819664f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1997126
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65728}
parent 8b7113bf
......@@ -1442,16 +1442,13 @@ void BytecodeGenerator::VisitGlobalDeclarations(Declaration::List* decls) {
globals_builder()->set_constant_pool_entry(
builder()->AllocateDeferredConstantPoolEntry());
int encoded_flags = DeclareGlobalsEvalFlag::encode(info()->is_eval());
// Emit code to declare globals.
RegisterList args = register_allocator()->NewRegisterList(3);
RegisterList args = register_allocator()->NewRegisterList(2);
builder()
->LoadConstantPoolEntry(globals_builder()->constant_pool_entry())
.StoreAccumulatorInRegister(args[0])
.LoadLiteral(Smi::FromInt(encoded_flags))
.StoreAccumulatorInRegister(args[1])
.MoveRegister(Register::function_closure(), args[2])
.MoveRegister(Register::function_closure(), args[1])
.CallRuntime(Runtime::kDeclareGlobals, args);
globals_builder()->mark_processed();
......
......@@ -119,7 +119,7 @@ Object DeclareGlobal(
}
Object DeclareGlobals(Isolate* isolate, Handle<FixedArray> declarations,
int flags, Handle<JSFunction> closure) {
Handle<JSFunction> closure) {
HandleScope scope(isolate);
Handle<JSGlobalObject> global(isolate->global_object());
Handle<Context> context(isolate->context(), isolate);
......@@ -160,15 +160,17 @@ Object DeclareGlobals(Isolate* isolate, Handle<FixedArray> declarations,
// Compute the property attributes. According to ECMA-262,
// the property must be non-configurable except in eval.
bool is_eval = DeclareGlobalsEvalFlag::decode(flags);
int attr = NONE;
if (!is_eval) attr |= DONT_DELETE;
Script script = Script::cast(closure->shared().script());
PropertyAttributes attr =
script.compilation_type() == Script::COMPILATION_TYPE_EVAL
? NONE
: DONT_DELETE;
// ES#sec-globaldeclarationinstantiation 5.d:
// If hasRestrictedGlobal is true, throw a SyntaxError exception.
Object result = DeclareGlobal(
isolate, global, name, value, static_cast<PropertyAttributes>(attr),
is_var, RedeclarationType::kSyntaxError, feedback_vector);
Object result =
DeclareGlobal(isolate, global, name, value, attr, is_var,
RedeclarationType::kSyntaxError, feedback_vector);
if (isolate->has_pending_exception()) return result;
});
......@@ -179,13 +181,12 @@ Object DeclareGlobals(Isolate* isolate, Handle<FixedArray> declarations,
RUNTIME_FUNCTION(Runtime_DeclareGlobals) {
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(FixedArray, declarations, 0);
CONVERT_SMI_ARG_CHECKED(flags, 1);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, closure, 2);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, closure, 1);
return DeclareGlobals(isolate, declarations, flags, closure);
return DeclareGlobals(isolate, declarations, closure);
}
namespace {
......
......@@ -387,7 +387,7 @@ namespace internal {
#define FOR_EACH_INTRINSIC_SCOPES(F, I) \
F(DeclareEvalFunction, 2, 1) \
F(DeclareEvalVar, 1, 1) \
F(DeclareGlobals, 3, 1) \
F(DeclareGlobals, 2, 1) \
F(DeleteLookupSlot, 1, 1) \
F(LoadLookupSlot, 1, 1) \
F(LoadLookupSlotInsideTypeof, 1, 1) \
......@@ -794,8 +794,6 @@ using AllocateDoubleAlignFlag = base::BitField<bool, 0, 1>;
using AllowLargeObjectAllocationFlag = base::BitField<bool, 1, 1>;
using DeclareGlobalsEvalFlag = base::BitField<bool, 0, 1>;
// A set of bits returned by Runtime_GetOptimizationStatus.
// These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
enum class OptimizationStatus {
......
......@@ -10,17 +10,15 @@ top level: yes
snippet: "
var a = 1;
"
frame size: 4
frame size: 3
parameter count: 1
bytecode array length: 23
bytecode array length: 20
bytecodes: [
/* 0 E> */ B(StackCheck),
B(LdaConstant), U8(0),
B(Star), R(1),
B(LdaZero),
B(Star), R(2),
B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(3),
B(Mov), R(closure), R(2),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2),
/* 8 S> */ B(LdaSmi), I8(1),
/* 8 E> */ B(StaGlobal), U8(1), U8(0),
B(LdaUndefined),
......@@ -37,17 +35,15 @@ handlers: [
snippet: "
function f() {}
"
frame size: 3
frame size: 2
parameter count: 1
bytecode array length: 18
bytecode array length: 15
bytecodes: [
/* 0 E> */ B(StackCheck),
B(LdaConstant), U8(0),
B(Star), R(0),
B(LdaZero),
B(Star), R(1),
B(Mov), R(closure), R(2),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(0), U8(3),
B(Mov), R(closure), R(1),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(0), U8(2),
B(LdaUndefined),
/* 16 S> */ B(Return),
]
......@@ -62,17 +58,15 @@ snippet: "
var a = 1;
a=2;
"
frame size: 4
frame size: 3
parameter count: 1
bytecode array length: 29
bytecode array length: 26
bytecodes: [
/* 0 E> */ B(StackCheck),
B(LdaConstant), U8(0),
B(Star), R(1),
B(LdaZero),
B(Star), R(2),
B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(3),
B(Mov), R(closure), R(2),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2),
/* 8 S> */ B(LdaSmi), I8(1),
/* 8 E> */ B(StaGlobal), U8(1), U8(0),
/* 11 S> */ B(LdaSmi), I8(2),
......@@ -92,17 +86,15 @@ snippet: "
function f() {}
f();
"
frame size: 4
frame size: 3
parameter count: 1
bytecode array length: 27
bytecode array length: 24
bytecodes: [
/* 0 E> */ B(StackCheck),
B(LdaConstant), U8(0),
B(Star), R(1),
B(LdaZero),
B(Star), R(2),
B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(3),
B(Mov), R(closure), R(2),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2),
/* 16 S> */ B(LdaGlobal), U8(1), U8(0),
B(Star), R(1),
/* 16 E> */ B(CallUndefinedReceiver0), R(1), U8(2),
......
......@@ -10,17 +10,15 @@ top level: yes
snippet: "
var a = { func: function() { } };
"
frame size: 4
frame size: 3
parameter count: 1
bytecode array length: 37
bytecode array length: 34
bytecodes: [
/* 0 E> */ B(StackCheck),
B(LdaConstant), U8(0),
B(Star), R(1),
B(LdaZero),
B(Star), R(2),
B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(3),
B(Mov), R(closure), R(2),
B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2),
/* 8 S> */ B(CreateObjectLiteral), U8(1), U8(0), U8(41),
B(Star), R(1),
/* 16 E> */ B(CreateClosure), U8(2), U8(0), U8(0),
......
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