/**
* Runs the script returning the resulting value. It will be run in the
* context in which it was created (ScriptCompiler::CompileBound or
- * UnboundScript::BindToGlobalContext()).
+ * UnboundScript::BindToCurrentContext()).
*/
Local<Value> Run();
function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate());
i::Handle<i::JSFunction> function =
obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo(
- function_info, obj->GetIsolate()->global_context());
+ function_info, obj->GetIsolate()->native_context());
return ToApiHandle<Script>(function);
}
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript(
str, name_obj, line_offset, column_offset, is_shared_cross_origin,
- isolate->global_context(), NULL, &script_data, options,
+ isolate->native_context(), NULL, &script_data, options,
i::NOT_NATIVES_CODE);
has_pending_exception = result.is_null();
if (has_pending_exception && script_data != NULL) {
ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript(
Isolate* v8_isolate, StreamedSource* source, CompileOptions options) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
- if (!isolate->global_context().is_null() &&
- !isolate->global_context()->IsNativeContext()) {
- // The context chain is non-trivial, and constructing the corresponding
- // non-trivial Scope chain outside the V8 heap is not implemented. Don't
- // stream the script. This will only occur if Harmony scoping is enabled and
- // a previous script has introduced "let" or "const" variables. TODO(marja):
- // Implement externalizing ScopeInfos and constructing non-trivial Scope
- // chains independent of the V8 heap so that we can stream also in this
- // case.
- return NULL;
- }
return new i::BackgroundParsingTask(source->impl(), options,
i::FLAG_stack_size, isolate);
}
v8::True(v8_isolate));
}
source->info->set_script(script);
- source->info->SetContext(isolate->global_context());
+ source->info->SetContext(isolate->native_context());
EXCEPTION_PREAMBLE(isolate);
// Argument to NewContext is the function, which is still in r1.
Comment cmnt(masm_, "[ Allocate context");
bool need_write_barrier = true;
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ push(r1);
__ Push(info->scope()->GetScopeInfo());
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(r1, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(r1, scope_->ContextChainLength(scope_->ScriptScope()));
__ ldr(r1, ContextOperand(r1, variable->interface()->Index()));
__ ldr(r1, ContextOperand(r1, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
// Argument to NewContext is the function, which is still in x1.
Comment cmnt(masm_, "[ Allocate context");
bool need_write_barrier = true;
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ Mov(x10, Operand(info->scope()->GetScopeInfo()));
__ Push(x1, x10);
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(x1, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(x1, scope_->ContextChainLength(scope_->ScriptScope()));
__ Ldr(x1, ContextMemOperand(x1, variable->interface()->Index()));
__ Ldr(x1, ContextMemOperand(x1, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
// Check the context is a native context.
if (emit_debug_code()) {
- // Read the first word and compare to the global_context_map.
+ // Read the first word and compare to the native_context_map.
Ldr(scratch2, FieldMemOperand(scratch1, HeapObject::kMapOffset));
CompareRoot(scratch2, Heap::kNativeContextMapRootIndex);
Check(eq, kExpectedNativeContext);
Handle<JSGlobalProxy> global_proxy) {
// Set the native context for the global object.
global_object->set_native_context(*native_context());
- global_object->set_global_context(*native_context());
global_object->set_global_proxy(*global_proxy);
global_proxy->set_native_context(*native_context());
native_context()->set_global_proxy(*global_proxy);
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
- Handle<GlobalContextTable> global_context_table =
- factory->NewGlobalContextTable();
- native_context()->set_global_context_table(*global_context_table);
+ Handle<ScriptContextTable> script_context_table =
+ factory->NewScriptContextTable();
+ native_context()->set_script_context_table(*script_context_table);
Handle<String> object_name = factory->Object_string();
JSObject::AddProperty(
Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun));
builtins->set_builtins(*builtins);
builtins->set_native_context(*native_context());
- builtins->set_global_context(*native_context());
builtins->set_global_proxy(native_context()->global_proxy());
template <>
-HValue* CodeStubGraphBuilder<LoadGlobalContextFieldStub>::BuildCodeStub() {
+HValue* CodeStubGraphBuilder<LoadScriptContextFieldStub>::BuildCodeStub() {
int context_index = casted_stub()->context_index();
int slot_index = casted_stub()->slot_index();
- HValue* global_context = BuildGetGlobalContext(context_index);
- return Add<HLoadNamedField>(global_context, static_cast<HValue*>(NULL),
+ HValue* script_context = BuildGetScriptContext(context_index);
+ return Add<HLoadNamedField>(script_context, static_cast<HValue*>(NULL),
HObjectAccess::ForContextSlot(slot_index));
}
-Handle<Code> LoadGlobalContextFieldStub::GenerateCode() {
+Handle<Code> LoadScriptContextFieldStub::GenerateCode() {
return DoGenerateCode(this);
}
template <>
-HValue* CodeStubGraphBuilder<StoreGlobalContextFieldStub>::BuildCodeStub() {
+HValue* CodeStubGraphBuilder<StoreScriptContextFieldStub>::BuildCodeStub() {
int context_index = casted_stub()->context_index();
int slot_index = casted_stub()->slot_index();
- HValue* global_context = BuildGetGlobalContext(context_index);
- Add<HStoreNamedField>(global_context,
+ HValue* script_context = BuildGetScriptContext(context_index);
+ Add<HStoreNamedField>(script_context,
HObjectAccess::ForContextSlot(slot_index),
GetParameter(2), STORE_TO_INITIALIZED_ENTRY);
return GetParameter(2);
}
-Handle<Code> StoreGlobalContextFieldStub::GenerateCode() {
+Handle<Code> StoreScriptContextFieldStub::GenerateCode() {
return DoGenerateCode(this);
}
V(InternalArrayNoArgumentConstructor) \
V(InternalArraySingleArgumentConstructor) \
V(KeyedLoadGeneric) \
- V(LoadGlobalContextField) \
+ V(LoadScriptContextField) \
V(LoadDictionaryElement) \
V(LoadFastElement) \
V(MegamorphicLoad) \
V(NumberToString) \
V(RegExpConstructResult) \
V(StoreFastElement) \
- V(StoreGlobalContextField) \
+ V(StoreScriptContextField) \
V(StringAdd) \
V(ToBoolean) \
V(TransitionElementsKind) \
};
-class GlobalContextFieldStub : public HandlerStub {
+class ScriptContextFieldStub : public HandlerStub {
public:
- GlobalContextFieldStub(Isolate* isolate,
- const GlobalContextTable::LookupResult* lookup_result)
+ ScriptContextFieldStub(Isolate* isolate,
+ const ScriptContextTable::LookupResult* lookup_result)
: HandlerStub(isolate) {
DCHECK(Accepted(lookup_result));
set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
- static bool Accepted(const GlobalContextTable::LookupResult* lookup_result) {
+ static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
return ContextIndexBits::is_valid(lookup_result->context_index) &&
SlotIndexBits::is_valid(lookup_result->slot_index);
}
virtual Code::StubType GetStubType() OVERRIDE { return Code::FAST; }
- DEFINE_CODE_STUB_BASE(GlobalContextFieldStub, HandlerStub);
+ DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
};
-class LoadGlobalContextFieldStub : public GlobalContextFieldStub {
+class LoadScriptContextFieldStub : public ScriptContextFieldStub {
public:
- LoadGlobalContextFieldStub(
- Isolate* isolate, const GlobalContextTable::LookupResult* lookup_result)
- : GlobalContextFieldStub(isolate, lookup_result) {}
+ LoadScriptContextFieldStub(
+ Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
+ : ScriptContextFieldStub(isolate, lookup_result) {}
private:
virtual Code::Kind kind() const OVERRIDE { return Code::LOAD_IC; }
- DEFINE_HANDLER_CODE_STUB(LoadGlobalContextField, GlobalContextFieldStub);
+ DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
};
-class StoreGlobalContextFieldStub : public GlobalContextFieldStub {
+class StoreScriptContextFieldStub : public ScriptContextFieldStub {
public:
- StoreGlobalContextFieldStub(
- Isolate* isolate, const GlobalContextTable::LookupResult* lookup_result)
- : GlobalContextFieldStub(isolate, lookup_result) {}
+ StoreScriptContextFieldStub(
+ Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
+ : ScriptContextFieldStub(isolate, lookup_result) {}
private:
virtual Code::Kind kind() const OVERRIDE { return Code::STORE_IC; }
- DEFINE_HANDLER_CODE_STUB(StoreGlobalContextField, GlobalContextFieldStub);
+ DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
};
isolate_ = isolate;
function_ = NULL;
scope_ = NULL;
- global_scope_ = NULL;
+ script_scope_ = NULL;
extension_ = NULL;
cached_data_ = NULL;
compile_options_ = ScriptCompiler::kNoCompileOptions;
result = CompileToplevel(&info);
if (extension == NULL && !result.is_null() && !result->dont_cache()) {
compilation_cache->PutScript(source, context, result);
- // TODO(yangguo): Issue 3628
- // With block scoping, top-level variables may resolve to a global,
- // context, which makes the code context-dependent.
- if (FLAG_serialize_toplevel && !FLAG_harmony_scoping &&
+ if (FLAG_serialize_toplevel &&
compile_options == ScriptCompiler::kProduceCodeCache) {
HistogramTimerScope histogram_timer(
isolate->counters()->compile_serialize());
}
FunctionLiteral* function() const { return function_; }
Scope* scope() const { return scope_; }
- Scope* global_scope() const { return global_scope_; }
+ Scope* script_scope() const { return script_scope_; }
Handle<Code> code() const { return code_; }
Handle<JSFunction> closure() const { return closure_; }
Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
function_ = literal;
}
void PrepareForCompilation(Scope* scope);
- void SetGlobalScope(Scope* global_scope) {
- DCHECK(global_scope_ == NULL);
- global_scope_ = global_scope;
+ void SetScriptScope(Scope* script_scope) {
+ DCHECK(script_scope_ == NULL);
+ script_scope_ = script_scope;
}
Handle<TypeFeedbackVector> feedback_vector() const {
return feedback_vector_;
// The scope of the function literal as a convenience. Set to indicate
// that scopes have been analyzed.
Scope* scope_;
- // The global scope provided as a convenience.
- Scope* global_scope_;
+ // The script scope provided as a convenience.
+ Scope* script_scope_;
// For compiled stubs, the stub object
HydrogenCodeStub* code_stub_;
// The compiled code.
ScriptData** cached_data_;
ScriptCompiler::CompileOptions compile_options_;
- // The context of the caller for eval code, and the global context for a
+ // The context of the caller for eval code, and the script context for a
// global script. Will be a null handle otherwise.
Handle<Context> context_;
REPLACE_RUNTIME_CALL(JSCreateWithContext, Runtime::kPushWithContext)
REPLACE_RUNTIME_CALL(JSCreateBlockContext, Runtime::kPushBlockContext)
REPLACE_RUNTIME_CALL(JSCreateModuleContext, Runtime::kPushModuleContext)
-REPLACE_RUNTIME_CALL(JSCreateGlobalContext, Runtime::kAbort)
+REPLACE_RUNTIME_CALL(JSCreateScriptContext, Runtime::kAbort)
#undef REPLACE_RUNTIME
V(CreateWithContext, Operator::kNoProperties, 2, 1) \
V(CreateBlockContext, Operator::kNoProperties, 2, 1) \
V(CreateModuleContext, Operator::kNoProperties, 2, 1) \
- V(CreateGlobalContext, Operator::kNoProperties, 2, 1)
+ V(CreateScriptContext, Operator::kNoProperties, 2, 1)
struct JSOperatorGlobalCache FINAL {
const Operator* CreateWithContext();
const Operator* CreateBlockContext();
const Operator* CreateModuleContext();
- const Operator* CreateGlobalContext();
+ const Operator* CreateScriptContext();
private:
Zone* zone() const { return zone_; }
V(JSCreateWithContext) \
V(JSCreateBlockContext) \
V(JSCreateModuleContext) \
- V(JSCreateGlobalContext)
+ V(JSCreateScriptContext)
#define JS_OTHER_OP_LIST(V) \
V(JSCallConstruct) \
}
-Bounds Typer::Visitor::TypeJSCreateGlobalContext(Node* node) {
+Bounds Typer::Visitor::TypeJSCreateScriptContext(Node* node) {
Bounds outer = ContextOperand(node);
return Bounds(Type::Context(outer.upper, zone()));
}
case IrOpcode::kJSCreateWithContext:
case IrOpcode::kJSCreateBlockContext:
case IrOpcode::kJSCreateModuleContext:
- case IrOpcode::kJSCreateGlobalContext: {
+ case IrOpcode::kJSCreateScriptContext: {
// Type is Context, and operand is Internal.
Node* context = NodeProperties::GetContextInput(node);
// TODO(rossberg): This should really be Is(Internal), but the typer
namespace internal {
-Handle<GlobalContextTable> GlobalContextTable::Extend(
- Handle<GlobalContextTable> table, Handle<Context> global_context) {
- Handle<GlobalContextTable> result;
+Handle<ScriptContextTable> ScriptContextTable::Extend(
+ Handle<ScriptContextTable> table, Handle<Context> script_context) {
+ Handle<ScriptContextTable> result;
int used = table->used();
int length = table->length();
CHECK(used >= 0 && length > 0 && used < length);
if (used + 1 == length) {
CHECK(length < Smi::kMaxValue / 2);
- result = Handle<GlobalContextTable>::cast(
+ result = Handle<ScriptContextTable>::cast(
FixedArray::CopySize(table, length * 2));
} else {
result = table;
}
result->set_used(used + 1);
- DCHECK(global_context->IsGlobalContext());
- result->set(used + 1, *global_context);
+ DCHECK(script_context->IsScriptContext());
+ result->set(used + 1, *script_context);
return result;
}
-bool GlobalContextTable::Lookup(Handle<GlobalContextTable> table,
+bool ScriptContextTable::Lookup(Handle<ScriptContextTable> table,
Handle<String> name, LookupResult* result) {
for (int i = 0; i < table->used(); i++) {
Handle<Context> context = GetContext(table, i);
- DCHECK(context->IsGlobalContext());
+ DCHECK(context->IsScriptContext());
Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension()));
int slot_index = ScopeInfo::ContextSlotIndex(
scope_info, name, &result->mode, &result->init_flag,
}
-Context* Context::global_context() {
+Context* Context::script_context() {
Context* current = this;
- while (!current->IsGlobalContext()) {
+ while (!current->IsScriptContext()) {
current = current->previous();
}
return current;
do {
if (FLAG_trace_contexts) {
PrintF(" - looking in context %p", reinterpret_cast<void*>(*context));
- if (context->IsGlobalContext()) PrintF(" (global context)");
+ if (context->IsScriptContext()) PrintF(" (script context)");
if (context->IsNativeContext()) PrintF(" (native context)");
PrintF("\n");
}
if (context->IsNativeContext()) {
if (FLAG_trace_contexts) {
- PrintF(" - trying other global contexts\n");
+ PrintF(" - trying other script contexts\n");
}
- // Try other global contexts.
- Handle<GlobalContextTable> global_contexts(
- context->global_object()->native_context()->global_context_table());
- GlobalContextTable::LookupResult r;
- if (GlobalContextTable::Lookup(global_contexts, name, &r)) {
+ // Try other script contexts.
+ Handle<ScriptContextTable> script_contexts(
+ context->global_object()->native_context()->script_context_table());
+ ScriptContextTable::LookupResult r;
+ if (ScriptContextTable::Lookup(script_contexts, name, &r)) {
if (FLAG_trace_contexts) {
- Handle<Context> c = GlobalContextTable::GetContext(global_contexts,
+ Handle<Context> c = ScriptContextTable::GetContext(script_contexts,
r.context_index);
- PrintF("=> found property in global context %d: %p\n",
+ PrintF("=> found property in script context %d: %p\n",
r.context_index, reinterpret_cast<void*>(*c));
}
*index = r.slot_index;
GetAttributesAndBindingFlags(r.mode, r.init_flag, attributes,
binding_flags);
- return GlobalContextTable::GetContext(global_contexts,
+ return ScriptContextTable::GetContext(script_contexts,
r.context_index);
}
}
// 2. Check the context proper if it has slots.
if (context->IsFunctionContext() || context->IsBlockContext() ||
- (FLAG_harmony_scoping && context->IsGlobalContext())) {
+ (FLAG_harmony_scoping && context->IsScriptContext())) {
// Use serialized scope information of functions and blocks to search
// for the context index.
Handle<ScopeInfo> scope_info;
if (child->GetIsolate()->bootstrapper()->IsActive()) return true;
if (!object->IsContext()) return false;
Context* context = Context::cast(object);
- return context->IsNativeContext() || context->IsGlobalContext() ||
+ return context->IsNativeContext() || context->IsScriptContext() ||
context->IsModuleContext() || !child->IsModuleContext();
}
V(ITERATOR_SYMBOL_INDEX, Symbol, iterator_symbol) \
V(UNSCOPABLES_SYMBOL_INDEX, Symbol, unscopables_symbol) \
V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
- V(GLOBAL_CONTEXT_TABLE_INDEX, GlobalContextTable, global_context_table)
+ V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table)
-// A table of all global contexts. Every loaded top-level script with top-level
-// lexical declarations contributes its GlobalContext into this table.
+// A table of all script contexts. Every loaded top-level script with top-level
+// lexical declarations contributes its ScriptContext into this table.
//
// The table is a fixed array, its first slot is the current used count and
-// the subsequent slots 1..used contain GlobalContexts.
-class GlobalContextTable : public FixedArray {
+// the subsequent slots 1..used contain ScriptContexts.
+class ScriptContextTable : public FixedArray {
public:
// Conversions.
- static GlobalContextTable* cast(Object* context) {
- DCHECK(context->IsGlobalContextTable());
- return reinterpret_cast<GlobalContextTable*>(context);
+ static ScriptContextTable* cast(Object* context) {
+ DCHECK(context->IsScriptContextTable());
+ return reinterpret_cast<ScriptContextTable*>(context);
}
struct LookupResult {
void set_used(int used) { set(kUsedSlot, Smi::FromInt(used)); }
- static Handle<Context> GetContext(Handle<GlobalContextTable> table, int i) {
+ static Handle<Context> GetContext(Handle<ScriptContextTable> table, int i) {
DCHECK(i < table->used());
return Handle<Context>::cast(FixedArray::get(table, i + 1));
}
- // Lookup a variable `name` in a GlobalContextTable.
+ // Lookup a variable `name` in a ScriptContextTable.
// If it returns true, the variable is found and `result` contains
// valid information about its location.
// If it returns false, `result` is untouched.
MUST_USE_RESULT
- static bool Lookup(Handle<GlobalContextTable> table, Handle<String> name,
+ static bool Lookup(Handle<ScriptContextTable> table, Handle<String> name,
LookupResult* result);
MUST_USE_RESULT
- static Handle<GlobalContextTable> Extend(Handle<GlobalContextTable> table,
- Handle<Context> global_context);
+ static Handle<ScriptContextTable> Extend(Handle<ScriptContextTable> table,
+ Handle<Context> script_context);
static int GetContextOffset(int context_index) {
return kFirstContextOffset + context_index * kPointerSize;
static const int kFirstContextOffset =
FixedArray::kHeaderSize + (kUsedSlot + 1) * kPointerSize;
- DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalContextTable);
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ScriptContextTable);
};
// JSFunctions are pairs (context, function code), sometimes also called
// properties.
//
// Finally, with Harmony scoping, the JSFunction representing a top level
-// script will have the GlobalContext rather than a FunctionContext.
-// Global contexts from all top-level scripts are gathered in
-// GlobalContextTable.
+// script will have the ScriptContext rather than a FunctionContext.
+// Script contexts from all top-level scripts are gathered in
+// ScriptContextTable.
class Context: public FixedArray {
public:
ITERATOR_SYMBOL_INDEX,
UNSCOPABLES_SYMBOL_INDEX,
ARRAY_VALUES_ITERATOR_INDEX,
- GLOBAL_CONTEXT_TABLE_INDEX,
+ SCRIPT_CONTEXT_TABLE_INDEX,
MAP_CACHE_INDEX,
// Properties from here are treated as weak references by the full GC.
// The builtins object.
JSBuiltinsObject* builtins();
- // Get the innermost global context by traversing the context chain.
- Context* global_context();
+ // Get the script context by traversing the context chain.
+ Context* script_context();
// Compute the native context by traversing the context chain.
Context* native_context();
Map* map = this->map();
return map == map->GetHeap()->module_context_map();
}
- bool IsGlobalContext() {
+ bool IsScriptContext() {
Map* map = this->map();
- return map == map->GetHeap()->global_context_map();
+ return map == map->GetHeap()->script_context_map();
}
bool HasSameSecurityTokenAs(Context* that) {
}
-Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function,
+Handle<Context> Factory::NewScriptContext(Handle<JSFunction> function,
Handle<ScopeInfo> scope_info) {
Handle<FixedArray> array =
NewFixedArray(scope_info->ContextLength(), TENURED);
- array->set_map_no_write_barrier(*global_context_map());
+ array->set_map_no_write_barrier(*script_context_map());
Handle<Context> context = Handle<Context>::cast(array);
context->set_closure(*function);
context->set_previous(function->context());
context->set_extension(*scope_info);
context->set_global_object(function->context()->global_object());
- DCHECK(context->IsGlobalContext());
+ DCHECK(context->IsScriptContext());
return context;
}
-Handle<GlobalContextTable> Factory::NewGlobalContextTable() {
+Handle<ScriptContextTable> Factory::NewScriptContextTable() {
Handle<FixedArray> array = NewFixedArray(1);
- array->set_map_no_write_barrier(*global_context_table_map());
- Handle<GlobalContextTable> context_table =
- Handle<GlobalContextTable>::cast(array);
+ array->set_map_no_write_barrier(*script_context_table_map());
+ Handle<ScriptContextTable> context_table =
+ Handle<ScriptContextTable>::cast(array);
context_table->set_used(0);
return context_table;
}
// Create a global (but otherwise uninitialized) context.
Handle<Context> NewNativeContext();
- // Create a global context.
- Handle<Context> NewGlobalContext(Handle<JSFunction> function,
+ // Create a script context.
+ Handle<Context> NewScriptContext(Handle<JSFunction> function,
Handle<ScopeInfo> scope_info);
- // Create an empty global context table.
- Handle<GlobalContextTable> NewGlobalContextTable();
+ // Create an empty script context table.
+ Handle<ScriptContextTable> NewScriptContextTable();
// Create a module context.
Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) {
- DCHECK(scope_->is_global_scope());
+ DCHECK(scope_->is_script_scope());
for (int i = 0; i < declarations->length(); i++) {
ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration();
// modules themselves, however, are simple data properties.)
//
// All modules have a _hosting_ scope/context, which (currently) is the
-// (innermost) enclosing global scope. To deal with recursion, nested modules
-// are hosted by the same scope as global ones.
+// enclosing script scope. To deal with recursion, nested modules are hosted
+// by the same scope as global ones.
//
// For every (global or nested) module literal, the hosting context has an
// internal slot that points directly to the respective module context. This
//
// To deal with arbitrary recursion and aliases between modules,
// they are created and initialized in several stages. Each stage applies to
-// all modules in the hosting global scope, including nested ones.
+// all modules in the hosting script scope, including nested ones.
//
// 1. Allocate: for each module _literal_, allocate the module contexts and
// respective instance object and wire them up. This happens in the
// This is a scope hosting modules. Allocate a descriptor array to pass
// to the runtime for initialization.
Comment cmnt(masm_, "[ Allocate modules");
- DCHECK(scope_->is_global_scope());
+ DCHECK(scope_->is_script_scope());
modules_ =
isolate()->factory()->NewFixedArray(scope_->num_modules(), TENURED);
module_index_ = 0;
EVAL_SCOPE, // The top-level scope for an eval source.
FUNCTION_SCOPE, // The top-level scope for a function.
MODULE_SCOPE, // The scope introduced by a module literal
- GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval.
+ SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval.
CATCH_SCOPE, // The scope introduced by catch.
BLOCK_SCOPE, // The scope introduced by a new block.
WITH_SCOPE, // The scope introduced by with.
SetInternalReference(global_obj, entry,
"native_context", global_obj->native_context(),
GlobalObject::kNativeContextOffset);
- SetInternalReference(global_obj, entry,
- "global_context", global_obj->global_context(),
- GlobalObject::kGlobalContextOffset);
SetInternalReference(global_obj, entry,
"global_proxy", global_obj->global_proxy(),
GlobalObject::kGlobalProxyOffset);
STATIC_ASSERT(GlobalObject::kHeaderSize - JSObject::kHeaderSize ==
- 4 * kPointerSize);
+ 3 * kPointerSize);
} else if (obj->IsJSArrayBufferView()) {
JSArrayBufferView* view = JSArrayBufferView::cast(obj);
SetInternalReference(view, entry, "buffer", view->buffer(),
ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, with_context)
ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, block_context)
ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_context)
- ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, global_context)
- ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, global_context_table)
+ ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, script_context)
+ ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, script_context_table)
ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, native_context)
native_context_map()->set_dictionary_map(true);
V(Map, with_context_map, WithContextMap) \
V(Map, block_context_map, BlockContextMap) \
V(Map, module_context_map, ModuleContextMap) \
- V(Map, global_context_map, GlobalContextMap) \
- V(Map, global_context_table_map, GlobalContextTableMap) \
+ V(Map, script_context_map, ScriptContextMap) \
+ V(Map, script_context_table_map, ScriptContextTableMap) \
V(Map, undefined_map, UndefinedMap) \
V(Map, the_hole_map, TheHoleMap) \
V(Map, null_map, NullMap) \
V(WithContextMap) \
V(BlockContextMap) \
V(ModuleContextMap) \
- V(GlobalContextMap) \
+ V(ScriptContextMap) \
V(UndefinedMap) \
V(TheHoleMap) \
V(NullMap) \
}
-HObjectAccess HObjectAccess::ForGlobalContext(int index) {
+HObjectAccess HObjectAccess::ForScriptContext(int index) {
DCHECK(index >= 0);
Portion portion = kInobject;
- int offset = GlobalContextTable::GetContextOffset(index);
+ int offset = ScriptContextTable::GetContextOffset(index);
return HObjectAccess(portion, offset, Representation::Tagged());
}
static HObjectAccess ForContextSlot(int index);
- static HObjectAccess ForGlobalContext(int index);
+ static HObjectAccess ForScriptContext(int index);
// Create an access to the backing store of an object.
static HObjectAccess ForBackingStoreOffset(int offset,
HInstruction* HGraphBuilder::BuildGetNativeContext(HValue* closure) {
- // Get the global context, then the native context
+ // Get the global object, then the native context
HInstruction* context =
Add<HLoadNamedField>(closure, static_cast<HValue*>(NULL),
HObjectAccess::ForFunctionContextPointer());
}
-HInstruction* HGraphBuilder::BuildGetGlobalContext(int context_index) {
+HInstruction* HGraphBuilder::BuildGetScriptContext(int context_index) {
HValue* native_context = BuildGetNativeContext();
- HValue* global_context_table = Add<HLoadNamedField>(
+ HValue* script_context_table = Add<HLoadNamedField>(
native_context, static_cast<HValue*>(NULL),
- HObjectAccess::ForContextSlot(Context::GLOBAL_CONTEXT_TABLE_INDEX));
- return Add<HLoadNamedField>(global_context_table, static_cast<HValue*>(NULL),
- HObjectAccess::ForGlobalContext(context_index));
+ HObjectAccess::ForContextSlot(Context::SCRIPT_CONTEXT_TABLE_INDEX));
+ return Add<HLoadNamedField>(script_context_table, static_cast<HValue*>(NULL),
+ HObjectAccess::ForScriptContext(context_index));
}
HInstruction* HGraphBuilder::BuildGetNativeContext() {
- // Get the global context, then the native context
+ // Get the global object, then the native context
HValue* global_object = Add<HLoadNamedField>(
context(), static_cast<HValue*>(NULL),
HObjectAccess::ForContextSlot(Context::GLOBAL_OBJECT_INDEX));
Scope* declaration_scope = scope->DeclarationScope();
HInstruction* function;
HValue* outer_context = environment()->context();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_eval_scope()) {
function = new(zone()) HLoadContextSlot(
outer_context, Context::CLOSURE_INDEX, HLoadContextSlot::kNoCheck);
Handle<GlobalObject> global(current_info()->global_object());
if (FLAG_harmony_scoping) {
- Handle<GlobalContextTable> global_contexts(
- global->native_context()->global_context_table());
- GlobalContextTable::LookupResult lookup;
- if (GlobalContextTable::Lookup(global_contexts, variable->name(),
+ Handle<ScriptContextTable> script_contexts(
+ global->native_context()->script_context_table());
+ ScriptContextTable::LookupResult lookup;
+ if (ScriptContextTable::Lookup(script_contexts, variable->name(),
&lookup)) {
- Handle<Context> global_context = GlobalContextTable::GetContext(
- global_contexts, lookup.context_index);
+ Handle<Context> script_context = ScriptContextTable::GetContext(
+ script_contexts, lookup.context_index);
HInstruction* result = New<HLoadNamedField>(
- Add<HConstant>(global_context), static_cast<HValue*>(NULL),
+ Add<HConstant>(script_context), static_cast<HValue*>(NULL),
HObjectAccess::ForContextSlot(lookup.slot_index));
return ast_context()->ReturnInstruction(result, expr->id());
}
Handle<GlobalObject> global(current_info()->global_object());
if (FLAG_harmony_scoping) {
- Handle<GlobalContextTable> global_contexts(
- global->native_context()->global_context_table());
- GlobalContextTable::LookupResult lookup;
- if (GlobalContextTable::Lookup(global_contexts, var->name(), &lookup)) {
- Handle<Context> global_context =
- GlobalContextTable::GetContext(global_contexts, lookup.context_index);
+ Handle<ScriptContextTable> script_contexts(
+ global->native_context()->script_context_table());
+ ScriptContextTable::LookupResult lookup;
+ if (ScriptContextTable::Lookup(script_contexts, var->name(), &lookup)) {
+ Handle<Context> script_context =
+ ScriptContextTable::GetContext(script_contexts, lookup.context_index);
HStoreNamedField* instr = Add<HStoreNamedField>(
- Add<HConstant>(global_context),
+ Add<HConstant>(script_context),
HObjectAccess::ForContextSlot(lookup.slot_index), value);
USE(instr);
DCHECK(instr->HasObservableSideEffects());
HInstruction* BuildGetNativeContext(HValue* closure);
HInstruction* BuildGetNativeContext();
- HInstruction* BuildGetGlobalContext(int context_index);
+ HInstruction* BuildGetScriptContext(int context_index);
HInstruction* BuildGetArrayFunction();
protected:
Comment cmnt(masm_, "[ Allocate context");
bool need_write_barrier = true;
// Argument to NewContext is the function, which is still in edi.
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ push(edi);
__ Push(info->scope()->GetScopeInfo());
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(eax, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(eax, scope_->ContextChainLength(scope_->ScriptScope()));
__ mov(eax, ContextOperand(eax, variable->interface()->Index()));
__ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
bool use_ic = MigrateDeprecated(object) ? false : FLAG_use_ic;
if (FLAG_harmony_scoping && object->IsGlobalObject() && name->IsString()) {
- // Look up in global context table.
+ // Look up in script context table.
Handle<String> str_name = Handle<String>::cast(name);
Handle<GlobalObject> global = Handle<GlobalObject>::cast(object);
- Handle<GlobalContextTable> global_contexts(
- global->native_context()->global_context_table());
+ Handle<ScriptContextTable> script_contexts(
+ global->native_context()->script_context_table());
- GlobalContextTable::LookupResult lookup_result;
- if (GlobalContextTable::Lookup(global_contexts, str_name, &lookup_result)) {
- if (use_ic && LoadGlobalContextFieldStub::Accepted(&lookup_result)) {
- LoadGlobalContextFieldStub stub(isolate(), &lookup_result);
+ ScriptContextTable::LookupResult lookup_result;
+ if (ScriptContextTable::Lookup(script_contexts, str_name, &lookup_result)) {
+ if (use_ic && LoadScriptContextFieldStub::Accepted(&lookup_result)) {
+ LoadScriptContextFieldStub stub(isolate(), &lookup_result);
PatchCache(name, stub.GetCode());
}
- return FixedArray::get(GlobalContextTable::GetContext(
- global_contexts, lookup_result.context_index),
+ return FixedArray::get(ScriptContextTable::GetContext(
+ script_contexts, lookup_result.context_index),
lookup_result.slot_index);
}
}
Handle<Object> value,
JSReceiver::StoreFromKeyed store_mode) {
if (FLAG_harmony_scoping && object->IsGlobalObject() && name->IsString()) {
- // Look up in global context table.
+ // Look up in script context table.
Handle<String> str_name = Handle<String>::cast(name);
Handle<GlobalObject> global = Handle<GlobalObject>::cast(object);
- Handle<GlobalContextTable> global_contexts(
- global->native_context()->global_context_table());
+ Handle<ScriptContextTable> script_contexts(
+ global->native_context()->script_context_table());
- GlobalContextTable::LookupResult lookup_result;
- if (GlobalContextTable::Lookup(global_contexts, str_name, &lookup_result)) {
- Handle<Context> global_context = GlobalContextTable::GetContext(
- global_contexts, lookup_result.context_index);
+ ScriptContextTable::LookupResult lookup_result;
+ if (ScriptContextTable::Lookup(script_contexts, str_name, &lookup_result)) {
+ Handle<Context> script_context = ScriptContextTable::GetContext(
+ script_contexts, lookup_result.context_index);
if (lookup_result.mode == CONST) {
return TypeError("harmony_const_assign", object, name);
}
if (FLAG_use_ic &&
- StoreGlobalContextFieldStub::Accepted(&lookup_result)) {
- StoreGlobalContextFieldStub stub(isolate(), &lookup_result);
+ StoreScriptContextFieldStub::Accepted(&lookup_result)) {
+ StoreScriptContextFieldStub stub(isolate(), &lookup_result);
PatchCache(name, stub.GetCode());
}
- global_context->set(lookup_result.slot_index, *value);
+ script_context->set(lookup_result.slot_index, *value);
return value;
}
}
return exports ? exports->occupancy() : 0;
}
- // The context slot in the hosting global context pointing to this module.
+ // The context slot in the hosting script context pointing to this module.
int Index() {
DCHECK(IsModule() && IsFrozen());
return Chase()->index_;
}
-Handle<Context> Isolate::global_context() {
- return handle(context()->global_object()->global_context());
-}
-
-
Handle<Context> Isolate::GetCallingNativeContext() {
JavaScriptFrameIterator it(this);
if (debug_->in_debug_scope()) {
void IterateThread(ThreadVisitor* v, char* t);
- // Returns the current native and global context.
+ // Returns the current native context.
Handle<Context> native_context();
- Handle<Context> global_context();
// Returns the native context of the calling JavaScript code. That
// is, the native context of the top-most JavaScript frame.
Comment cmnt(masm_, "[ Allocate context");
// Argument to NewContext is the function, which is still in a1.
bool need_write_barrier = true;
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ push(a1);
__ Push(info->scope()->GetScopeInfo());
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(a1, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(a1, scope_->ContextChainLength(scope_->ScriptScope()));
__ lw(a1, ContextOperand(a1, variable->interface()->Index()));
__ lw(a1, ContextOperand(a1, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
Comment cmnt(masm_, "[ Allocate context");
// Argument to NewContext is the function, which is still in a1.
bool need_write_barrier = true;
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ push(a1);
__ Push(info->scope()->GetScopeInfo());
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(a1, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(a1, scope_->ContextChainLength(scope_->ScriptScope()));
__ ld(a1, ContextOperand(a1, variable->interface()->Index()));
__ ld(a1, ContextOperand(a1, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
map == heap->native_context_map() ||
map == heap->block_context_map() ||
map == heap->module_context_map() ||
- map == heap->global_context_map());
+ map == heap->script_context_map());
}
}
-bool Object::IsGlobalContextTable() const {
+bool Object::IsScriptContextTable() const {
if (!Object::IsHeapObject()) return false;
Map* map = HeapObject::cast(this)->map();
Heap* heap = map->GetHeap();
- return map == heap->global_context_table_map();
+ return map == heap->script_context_table_map();
}
ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset)
ACCESSORS(GlobalObject, native_context, Context, kNativeContextOffset)
-ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset)
ACCESSORS(GlobalObject, global_proxy, JSObject, kGlobalProxyOffset)
ACCESSORS(JSGlobalProxy, native_context, Object, kNativeContextOffset)
if (context->has_extension() && !context->IsCatchContext()) {
// With harmony scoping, a JSFunction may have a global context.
// TODO(mvstanton): walk into the ScopeInfo.
- if (FLAG_harmony_scoping && context->IsGlobalContext()) {
+ if (FLAG_harmony_scoping && context->IsScriptContext()) {
return false;
}
// - JSFunctionResultCache
// - ScopeInfo
// - TransitionArray
-// - GlobalContextTable
+// - ScriptContextTable
// - FixedDoubleArray
// - ExternalArray
// - ExternalUint8ClampedArray
V(FixedDoubleArray) \
V(ConstantPoolArray) \
V(Context) \
- V(GlobalContextTable) \
+ V(ScriptContextTable) \
V(NativeContext) \
V(ScopeInfo) \
V(JSFunction) \
// [native context]: the natives corresponding to this global object.
DECL_ACCESSORS(native_context, Context)
- // [global context]: the most recent (i.e. innermost) global context.
- DECL_ACCESSORS(global_context, Context)
-
// [global proxy]: the global proxy object of the context
DECL_ACCESSORS(global_proxy, JSObject)
// Layout description.
static const int kBuiltinsOffset = JSObject::kHeaderSize;
static const int kNativeContextOffset = kBuiltinsOffset + kPointerSize;
- static const int kGlobalContextOffset = kNativeContextOffset + kPointerSize;
- static const int kGlobalProxyOffset = kGlobalContextOffset + kPointerSize;
+ static const int kGlobalProxyOffset = kNativeContextOffset + kPointerSize;
static const int kHeaderSize = kGlobalProxyOffset + kPointerSize;
private:
FunctionLiteral* result = NULL;
{
- *scope = NewScope(scope_, GLOBAL_SCOPE);
- info->SetGlobalScope(*scope);
+ *scope = NewScope(scope_, SCRIPT_SCOPE);
+ info->SetScriptScope(*scope);
if (!info->context().is_null() && !info->context()->IsNativeContext()) {
*scope = Scope::DeserializeScopeChain(*info->context(), *scope, zone());
// The Scope is backed up by ScopeInfo (which is in the V8 heap); this
}
original_scope_ = *scope;
if (info->is_eval()) {
- if (!(*scope)->is_global_scope() || info->strict_mode() == STRICT) {
+ if (!(*scope)->is_script_scope() || info->strict_mode() == STRICT) {
*scope = NewScope(*scope, EVAL_SCOPE);
}
} else if (info->is_global()) {
- *scope = NewScope(*scope, GLOBAL_SCOPE);
+ *scope = NewScope(*scope, SCRIPT_SCOPE);
}
(*scope)->set_start_position(0);
// End position will be set by the caller.
{
// Parse the function literal.
- Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
- info()->SetGlobalScope(scope);
+ Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
+ info()->SetScriptScope(scope);
if (!info()->closure().is_null()) {
scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
zone());
// all over the code base, so we go with a quick-fix for now.
// In the same manner, we have to patch the parsing mode.
if (is_eval && !scope_->is_eval_scope()) {
- DCHECK(scope_->is_global_scope());
+ DCHECK(scope_->is_script_scope());
Scope* scope = NewScope(scope_, EVAL_SCOPE);
scope->set_start_position(scope_->start_position());
scope->set_end_position(scope_->end_position());
declaration_scope->is_strict_eval_scope() ||
declaration_scope->is_block_scope() ||
declaration_scope->is_module_scope() ||
- declaration_scope->is_global_scope()) {
+ declaration_scope->is_script_scope()) {
// Declare the variable in the declaration scope.
- // For the global scope, we have to check for collisions with earlier
- // (i.e., enclosing) global scopes, to maintain the illusion of a single
- // global scope.
- var = declaration_scope->is_global_scope()
- ? declaration_scope->Lookup(name)
- : declaration_scope->LookupLocal(name);
+ var = declaration_scope->LookupLocal(name);
if (var == NULL) {
// Declare the name.
var = declaration_scope->DeclareLocal(name, mode,
kNotAssigned, proxy->interface());
} else if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(var->mode())
|| ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) &&
- !declaration_scope->is_global_scope())) {
+ !declaration_scope->is_script_scope())) {
// The name was declared in this scope before; check for conflicting
// re-declarations. We have a conflict if either of the declarations is
- // not a var (in the global scope, we also have to ignore legacy const for
+ // not a var (in script scope, we also have to ignore legacy const for
// compatibility). There is similar code in runtime.cc in the Declare
// functions. The function CheckConflictingVarDeclarations checks for
// var and let bindings from different scopes whereas this is a check for
// RuntimeHidden_DeclareLookupSlot calls.
declaration_scope->AddDeclaration(declaration);
- if (mode == CONST_LEGACY && declaration_scope->is_global_scope()) {
+ if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) {
// For global const variables we bind the proxy to a variable.
DCHECK(resolve); // should be set by all callers
Variable::Kind kind = Variable::NORMAL;
// Even if we're not at the top-level of the global or a function
// scope, we treat it as such and introduce the function with its
// initial value upon entering the corresponding scope.
- // In ES6, a function behaves as a lexical binding, except in the
- // global scope, or the initial scope of eval or another function.
+ // In ES6, a function behaves as a lexical binding, except in
+ // a script scope, or the initial scope of eval or another function.
VariableMode mode =
allow_harmony_scoping() && strict_mode() == STRICT &&
- !(scope_->is_global_scope() || scope_->is_eval_scope() ||
+ !(scope_->is_script_scope() || scope_->is_eval_scope() ||
scope_->is_function_scope()) ? LET : VAR;
VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
Declaration* declaration =
// declaration statement has been executed. This is important in
// browsers where the global object (window) has lots of
// properties defined in prototype objects.
- if (initialization_scope->is_global_scope() &&
+ if (initialization_scope->is_script_scope() &&
!IsLexicalVariableMode(mode)) {
// Compute the arguments for the runtime call.
ZoneList<Expression*>* arguments =
}
Scope* decl_scope = scope_->DeclarationScope();
- if (decl_scope->is_global_scope() || decl_scope->is_eval_scope()) {
+ if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) {
ReportMessageAt(loc, "illegal_return");
*ok = false;
return NULL;
static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
Scope* scope, ObjectLiteralProperty* property, bool* has_function) {
Expression* value = property->value();
- if (scope->DeclarationScope()->is_global_scope() &&
+ if (scope->DeclarationScope()->is_script_scope() &&
value->AsFunctionLiteral() != NULL) {
*has_function = true;
value->AsFunctionLiteral()->set_pretenure();
// Argument to NewContext is the function, which is still in r4.
Comment cmnt(masm_, "[ Allocate context");
bool need_write_barrier = true;
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ push(r4);
__ Push(info->scope()->GetScopeInfo());
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(r4, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(r4, scope_->ContextChainLength(scope_->ScriptScope()));
__ LoadP(r4, ContextOperand(r4, variable->interface()->Index()));
__ LoadP(r4, ContextOperand(r4, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
StrictMode strict_mode, bool is_generator, ParserRecorder* log) {
log_ = log;
// Lazy functions always have trivial outer scopes (no with/catch scopes).
- PreParserScope top_scope(scope_, GLOBAL_SCOPE);
+ PreParserScope top_scope(scope_, SCRIPT_SCOPE);
PreParserFactory top_factory(NULL);
FunctionState top_state(&function_state_, &scope_, &top_scope, &top_factory);
scope_->SetStrictMode(strict_mode);
// See Parser::ParseFunctionLiteral for more information about lazy parsing
// and lazy compilation.
- bool is_lazily_parsed = (outer_scope_type == GLOBAL_SCOPE && allow_lazy() &&
+ bool is_lazily_parsed = (outer_scope_type == SCRIPT_SCOPE && allow_lazy() &&
!parenthesized_function_);
parenthesized_function_ = false;
// captured the syntax error), and false if a stack-overflow happened
// during parsing.
PreParseResult PreParseProgram() {
- PreParserScope scope(scope_, GLOBAL_SCOPE);
+ PreParserScope scope(scope_, SCRIPT_SCOPE);
PreParserFactory factory(NULL);
FunctionState top_scope(&function_state_, &scope_, &scope, &factory);
bool ok = true;
DCHECK(function != NULL);
Scope* scope = function->scope();
DCHECK(scope != NULL);
- if (!scope->is_global_scope() && !scope->is_eval_scope()) return true;
+ if (!scope->is_script_scope() && !scope->is_eval_scope()) return true;
ZoneList<Statement*>* body = function->body();
if (!body->is_empty()) {
scope_info->scope_type() != ARROW_SCOPE) {
// Global or eval code.
CompilationInfoWithZone info(script);
- if (scope_info->scope_type() == GLOBAL_SCOPE) {
+ if (scope_info->scope_type() == SCRIPT_SCOPE) {
info.MarkAsGlobal();
} else {
DCHECK(scope_info->scope_type() == EVAL_SCOPE);
case MODULE_SCOPE:
DCHECK(context_->IsModuleContext());
return ScopeTypeModule;
- case GLOBAL_SCOPE:
+ case SCRIPT_SCOPE:
DCHECK(context_->IsNativeContext());
return ScopeTypeGlobal;
case WITH_SCOPE:
Handle<String> name, Handle<Object> value,
PropertyAttributes attr, bool is_var,
bool is_const, bool is_function) {
- Handle<GlobalContextTable> global_contexts(
- global->native_context()->global_context_table());
- GlobalContextTable::LookupResult lookup;
- if (GlobalContextTable::Lookup(global_contexts, name, &lookup) &&
+ Handle<ScriptContextTable> script_contexts(
+ global->native_context()->script_context_table());
+ ScriptContextTable::LookupResult lookup;
+ if (ScriptContextTable::Lookup(script_contexts, name, &lookup) &&
IsLexicalVariableMode(lookup.mode)) {
return ThrowRedeclarationError(isolate, name);
}
HandleScope scope(isolate);
DCHECK(args.length() == 4);
- // Declarations are always made in a function, native, or global context. In
+ // Declarations are always made in a function, eval or script context. In
// the case of eval code, the context passed is the context of the caller,
// which may be some nested context and not the declaration context.
CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 0);
static Object* FindNameClash(Handle<ScopeInfo> scope_info,
Handle<GlobalObject> global_object,
- Handle<GlobalContextTable> global_context) {
+ Handle<ScriptContextTable> script_context) {
Isolate* isolate = scope_info->GetIsolate();
for (int var = 0; var < scope_info->ContextLocalCount(); var++) {
Handle<String> name(scope_info->ContextLocalName(var));
VariableMode mode = scope_info->ContextLocalMode(var);
- GlobalContextTable::LookupResult lookup;
- if (GlobalContextTable::Lookup(global_context, name, &lookup)) {
+ ScriptContextTable::LookupResult lookup;
+ if (ScriptContextTable::Lookup(script_context, name, &lookup)) {
if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) {
return ThrowRedeclarationError(isolate, name);
}
}
-RUNTIME_FUNCTION(Runtime_NewGlobalContext) {
+RUNTIME_FUNCTION(Runtime_NewScriptContext) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1);
Handle<GlobalObject> global_object(function->context()->global_object());
Handle<Context> native_context(global_object->native_context());
- Handle<GlobalContextTable> global_context_table(
- native_context->global_context_table());
+ Handle<ScriptContextTable> script_context_table(
+ native_context->script_context_table());
Handle<String> clashed_name;
Object* name_clash_result =
- FindNameClash(scope_info, global_object, global_context_table);
+ FindNameClash(scope_info, global_object, script_context_table);
if (isolate->has_pending_exception()) return name_clash_result;
Handle<Context> result =
- isolate->factory()->NewGlobalContext(function, scope_info);
+ isolate->factory()->NewScriptContext(function, scope_info);
DCHECK(function->context() == isolate->context());
DCHECK(function->context()->global_object() == result->global_object());
- Handle<GlobalContextTable> new_global_context_table =
- GlobalContextTable::Extend(global_context_table, result);
- native_context->set_global_context_table(*new_global_context_table);
+ Handle<ScriptContextTable> new_script_context_table =
+ ScriptContextTable::Extend(script_context_table, result);
+ native_context->set_script_context_table(*new_script_context_table);
return *result;
}
if (!args[1]->IsScopeInfo()) {
// Module already initialized. Find hosting context and retrieve context.
- Context* host = Context::cast(isolate->context())->global_context();
+ Context* host = Context::cast(isolate->context())->script_context();
Context* context = Context::cast(host->get(index));
DCHECK(context->previous() == isolate->context());
isolate->set_context(context);
isolate->set_context(*context);
// Find hosting scope and initialize internal variable holding module there.
- previous->global_context()->set(index, *context);
+ previous->script_context()->set(index, *context);
return *context;
}
F(PromoteScheduledException, 0, 1) \
\
/* Contexts */ \
- F(NewGlobalContext, 2, 1) \
+ F(NewScriptContext, 2, 1) \
F(NewFunctionContext, 1, 1) \
F(PushWithContext, 2, 1) \
F(PushCatchContext, 3, 1) \
unresolved_(16, zone),
decls_(4, zone),
interface_(FLAG_harmony_modules &&
- (scope_type == MODULE_SCOPE || scope_type == GLOBAL_SCOPE)
+ (scope_type == MODULE_SCOPE || scope_type == SCRIPT_SCOPE)
? Interface::NewModule(zone) : NULL),
already_resolved_(false),
ast_value_factory_(ast_value_factory),
zone_(zone) {
SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null());
- // The outermost scope must be a global scope.
- DCHECK(scope_type == GLOBAL_SCOPE || outer_scope != NULL);
+ // The outermost scope must be a script scope.
+ DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL);
DCHECK(!HasIllegalRedeclaration());
}
}
-Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope,
+Scope* Scope::DeserializeScopeChain(Context* context, Scope* script_scope,
Zone* zone) {
// Reconstruct the outer scope chain from a closure's context chain.
Scope* current_scope = NULL;
Scope* with_scope = new(zone) Scope(current_scope,
WITH_SCOPE,
Handle<ScopeInfo>::null(),
- global_scope->ast_value_factory_,
+ script_scope->ast_value_factory_,
zone);
current_scope = with_scope;
// All the inner scopes are inside a with.
for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) {
s->scope_inside_with_ = true;
}
- } else if (context->IsGlobalContext()) {
+ } else if (context->IsScriptContext()) {
ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
current_scope = new(zone) Scope(current_scope,
- GLOBAL_SCOPE,
+ SCRIPT_SCOPE,
Handle<ScopeInfo>(scope_info),
- global_scope->ast_value_factory_,
+ script_scope->ast_value_factory_,
zone);
} else if (context->IsModuleContext()) {
ScopeInfo* scope_info = ScopeInfo::cast(context->module()->scope_info());
current_scope = new(zone) Scope(current_scope,
MODULE_SCOPE,
Handle<ScopeInfo>(scope_info),
- global_scope->ast_value_factory_,
+ script_scope->ast_value_factory_,
zone);
} else if (context->IsFunctionContext()) {
ScopeInfo* scope_info = context->closure()->shared()->scope_info();
current_scope = new(zone) Scope(current_scope,
FUNCTION_SCOPE,
Handle<ScopeInfo>(scope_info),
- global_scope->ast_value_factory_,
+ script_scope->ast_value_factory_,
zone);
if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true;
if (scope_info->IsAsmModule()) current_scope->asm_module_ = true;
current_scope = new(zone) Scope(current_scope,
BLOCK_SCOPE,
Handle<ScopeInfo>(scope_info),
- global_scope->ast_value_factory_,
+ script_scope->ast_value_factory_,
zone);
} else {
DCHECK(context->IsCatchContext());
String* name = String::cast(context->extension());
current_scope = new (zone) Scope(
current_scope,
- global_scope->ast_value_factory_->GetString(Handle<String>(name)),
- global_scope->ast_value_factory_, zone);
+ script_scope->ast_value_factory_->GetString(Handle<String>(name)),
+ script_scope->ast_value_factory_, zone);
}
if (contains_with) current_scope->RecordWithStatement();
if (innermost_scope == NULL) innermost_scope = current_scope;
context = context->previous();
}
- global_scope->AddInnerScope(current_scope);
- global_scope->PropagateScopeInfo(false);
- return (innermost_scope == NULL) ? global_scope : innermost_scope;
+ script_scope->AddInnerScope(current_scope);
+ script_scope->PropagateScopeInfo(false);
+ return (innermost_scope == NULL) ? script_scope : innermost_scope;
}
// Traverse the scope tree up to the first unresolved scope or the global
// scope and start scope resolution and variable allocation from that scope.
- while (!top->is_global_scope() &&
+ while (!top->is_script_scope() &&
!top->outer_scope()->already_resolved()) {
top = top->outer_scope();
}
scope->Print();
}
- if (FLAG_harmony_modules && FLAG_print_interfaces && top->is_global_scope()) {
+ if (FLAG_harmony_modules && FLAG_print_interfaces && top->is_script_scope()) {
PrintF("global : ");
top->interface()->Print();
}
}
// Declare convenience variables.
- // Declare and allocate receiver (even for the global scope, and even
+ // Declare and allocate receiver (even for the script scope, and even
// if naccesses_ == 0).
- // NOTE: When loading parameters in the global scope, we must take
+ // NOTE: When loading parameters in the script scope, we must take
// care not to access them as properties of the global object, but
// instead load them directly from the stack. Currently, the only
// such parameter is 'this' which is passed on the stack when
Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) {
- DCHECK(is_global_scope());
+ DCHECK(is_script_scope());
return variables_.Declare(this,
name,
DYNAMIC_GLOBAL,
PropagateScopeInfo(outer_scope_calls_sloppy_eval);
// 2) Allocate module instances.
- if (FLAG_harmony_modules && (is_global_scope() || is_module_scope())) {
+ if (FLAG_harmony_modules && (is_script_scope() || is_module_scope())) {
DCHECK(num_modules_ == 0);
AllocateModulesRecursively(this);
}
}
-Scope* Scope::GlobalScope() {
+Scope* Scope::ScriptScope() {
Scope* scope = this;
- while (!scope->is_global_scope()) {
+ while (!scope->is_script_scope()) {
scope = scope->outer_scope();
}
return scope;
case EVAL_SCOPE: return "eval";
case FUNCTION_SCOPE: return "function";
case MODULE_SCOPE: return "module";
- case GLOBAL_SCOPE: return "global";
+ case SCRIPT_SCOPE: return "global";
case CATCH_SCOPE: return "catch";
case BLOCK_SCOPE: return "block";
case WITH_SCOPE: return "with";
var->ForceContextAllocation();
}
} else {
- DCHECK(is_global_scope());
+ DCHECK(is_script_scope());
}
if (is_with_scope()) {
bool Scope::ResolveVariable(CompilationInfo* info,
VariableProxy* proxy,
AstNodeFactory<AstNullVisitor>* factory) {
- DCHECK(info->global_scope()->is_global_scope());
+ DCHECK(info->script_scope()->is_script_scope());
// If the proxy is already resolved there's nothing to do
// (functions and consts may be resolved by the parser).
case UNBOUND:
// No binding has been found. Declare a variable on the global object.
- var = info->global_scope()->DeclareDynamicGlobal(proxy->raw_name());
+ var = info->script_scope()->DeclareDynamicGlobal(proxy->raw_name());
break;
case UNBOUND_EVAL_SHADOWED:
bool Scope::ResolveVariablesRecursively(
CompilationInfo* info,
AstNodeFactory<AstNullVisitor>* factory) {
- DCHECK(info->global_scope()->is_global_scope());
+ DCHECK(info->script_scope()->is_script_scope());
// Resolve unresolved variables for this scope.
for (int i = 0; i < unresolved_.length(); i++) {
is_catch_scope() ||
is_block_scope() ||
is_module_scope() ||
- is_global_scope())) {
+ is_script_scope())) {
var->set_is_used();
if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned();
}
if (var->mode() == TEMPORARY) return false;
if (var->mode() == INTERNAL) return true;
if (is_catch_scope() || is_block_scope() || is_module_scope()) return true;
- if (is_global_scope() && IsLexicalVariableMode(var->mode())) return true;
+ if (is_script_scope() && IsLexicalVariableMode(var->mode())) return true;
return var->has_forced_context_allocation() ||
scope_calls_eval_ ||
inner_scope_calls_eval_ ||
// doesn't re-allocate variables repeatedly.
static bool Analyze(CompilationInfo* info);
- static Scope* DeserializeScopeChain(Context* context, Scope* global_scope,
+ static Scope* DeserializeScopeChain(Context* context, Scope* script_scope,
Zone* zone);
// The scope name is only used for printing/debugging.
Interface* interface = Interface::NewValue());
// Declare an implicit global variable in this scope which must be a
- // global scope. The variable was introduced (possibly from an inner
+ // script scope. The variable was introduced (possibly from an inner
// scope) by a reference to an unresolved variable with no intervening
// with statements or eval calls.
Variable* DeclareDynamicGlobal(const AstRawString* name);
void RecordWithStatement() { scope_contains_with_ = true; }
// Inform the scope that the corresponding code contains an eval call.
- void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; }
+ void RecordEvalCall() { if (!is_script_scope()) scope_calls_eval_ = true; }
// Inform the scope that the corresponding code uses "arguments".
void RecordArgumentsUsage() { scope_uses_arguments_ = true; }
return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE;
}
bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; }
- bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; }
+ bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; }
bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; }
bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; }
bool is_with_scope() const { return scope_type_ == WITH_SCOPE; }
bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; }
bool is_declaration_scope() const {
return is_eval_scope() || is_function_scope() ||
- is_module_scope() || is_global_scope();
+ is_module_scope() || is_script_scope();
}
bool is_strict_eval_scope() const {
return is_eval_scope() && strict_mode_ == STRICT;
int StackLocalCount() const;
int ContextLocalCount() const;
- // For global scopes, the number of module literals (including nested ones).
+ // For script scopes, the number of module literals (including nested ones).
int num_modules() const { return num_modules_; }
// For module scopes, the host scope's internal variable binding this module.
// The number of contexts between this and scope; zero if this == scope.
int ContextChainLength(Scope* scope);
- // Find the innermost global scope.
- Scope* GlobalScope();
+ // Find the script scope.
+ // Used in modules implemenetation to find hosting scope.
+ // TODO(rossberg): is this needed?
+ Scope* ScriptScope();
// Find the first function, global, or eval scope. This is the scope
// where var declarations will be hoisted to in the implementation.
// The variables declared in this scope:
//
- // All user-declared variables (incl. parameters). For global scopes
+ // All user-declared variables (incl. parameters). For script scopes
// variables may be implicitly 'declared' by being used (possibly in
// an inner scope) with no intervening with statements or eval calls.
VariableMap variables_;
// The variable reference could not be statically resolved to any binding
// and thus should be considered referencing a global variable. NULL is
// returned. The variable reference is not inside any 'with' statement and
- // no scope between the reference scope (inclusive) and global scope
+ // no scope between the reference scope (inclusive) and script scope
// (exclusive) makes a sloppy 'eval' call.
UNBOUND,
// The variable reference could not be statically resolved to any binding
// NULL is returned. The variable reference is not inside any 'with'
// statement, but some scope between the reference scope (inclusive) and
- // global scope (exclusive) makes a sloppy 'eval' call, that might
+ // script scope (exclusive) makes a sloppy 'eval' call, that might
// possibly introduce a variable binding. Thus the reference should be
// considered referencing a global variable unless it is shadowed by an
// 'eval' introduced binding.
// activation frame.
return (IsDynamicVariableMode(mode_) ||
(IsDeclaredVariableMode(mode_) && !IsLexicalVariableMode(mode_)))
- && scope_ != NULL && scope_->is_global_scope();
+ && scope_ != NULL && scope_->is_script_scope();
}
// The source code for an eval() call may refer to a variable that is
// in an outer scope about which we don't know anything (it may not
- // be the global scope). scope() is NULL in that case. Currently the
+ // be the script scope). scope() is NULL in that case. Currently the
// scope is only used to follow the context chain length.
Scope* scope() const { return scope_; }
Comment cmnt(masm_, "[ Allocate context");
bool need_write_barrier = true;
// Argument to NewContext is the function, which is still in rdi.
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ Push(rdi);
__ Push(info->scope()->GetScopeInfo());
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(rax, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(rax, scope_->ContextChainLength(scope_->ScriptScope()));
__ movp(rax, ContextOperand(rax, variable->interface()->Index()));
__ movp(rax, ContextOperand(rax, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
Comment cmnt(masm_, "[ Allocate context");
bool need_write_barrier = true;
// Argument to NewContext is the function, which is still in edi.
- if (FLAG_harmony_scoping && info->scope()->is_global_scope()) {
+ if (FLAG_harmony_scoping && info->scope()->is_script_scope()) {
__ push(edi);
__ Push(info->scope()->GetScopeInfo());
- __ CallRuntime(Runtime::kNewGlobalContext, 2);
+ __ CallRuntime(Runtime::kNewScriptContext, 2);
} else if (heap_slots <= FastNewContextStub::kMaximumSlots) {
FastNewContextStub stub(isolate(), heap_slots);
__ CallStub(&stub);
EmitDebugCheckDeclarationContext(variable);
// Load instance object.
- __ LoadContext(eax, scope_->ContextChainLength(scope_->GlobalScope()));
+ __ LoadContext(eax, scope_->ContextChainLength(scope_->ScriptScope()));
__ mov(eax, ContextOperand(eax, variable->interface()->Index()));
__ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX));
void FullCodeGenerator::PushFunctionArgumentForContextAllocation() {
Scope* declaration_scope = scope()->DeclarationScope();
- if (declaration_scope->is_global_scope() ||
+ if (declaration_scope->is_script_scope() ||
declaration_scope->is_module_scope()) {
// Contexts nested in the native context have a canonical empty function
// as their closure, not the anonymous closure containing the global
EXPECT_RESULT, Number::New(isolate, 1));
context.Check("'use strict'; let y1 = 3; 0;",
EXPECT_RESULT, Number::New(isolate, 0));
- // TODO(dslomov): still returns 1 not 3
- // context.Check(script1,
- // EXPECT_RESULT, Number::New(isolate, 3));
+ context.Check(script1,
+ EXPECT_RESULT, Number::New(isolate, 3));
context.Check("y1 = 4;",
EXPECT_RESULT, Number::New(isolate, 4));
- // TODO(dslomov): still returns 1 not 4
- // context.Check(script1,
- // EXPECT_RESULT, Number::New(isolate, 4));
+ context.Check(script1,
+ EXPECT_RESULT, Number::New(isolate, 4));
context.Check(script2,
EXPECT_RESULT, Number::New(isolate, 2));
context.Check("'use strict'; let y2 = 5; 0;",
EXPECT_RESULT, Number::New(isolate, 0));
- // TODO(dslomov): still returns 1 not 4
- // context.Check(script1,
- // EXPECT_RESULT, Number::New(isolate, 4));
- // TODO(dslomov): still returns 2 not 5
- // context.Check(script2,
- // EXPECT_RESULT, Number::New(isolate, 5));
+ context.Check(script1,
+ EXPECT_RESULT, Number::New(isolate, 4));
+ context.Check(script2,
+ EXPECT_RESULT, Number::New(isolate, 5));
}
}
const v8::HeapGraphNode* native_context =
GetProperty(global, v8::HeapGraphEdge::kInternal, "native_context");
CHECK_NE(NULL, native_context);
- const v8::HeapGraphNode* global_context =
- GetProperty(global, v8::HeapGraphEdge::kInternal, "global_context");
- CHECK_NE(NULL, global_context);
const v8::HeapGraphNode* global_proxy =
GetProperty(global, v8::HeapGraphEdge::kInternal, "global_proxy");
CHECK_NE(NULL, global_proxy);
CHECK(i::Scope::Analyze(&info));
CHECK(info.function() != NULL);
- i::Scope* global_scope = info.function()->scope();
- CHECK(global_scope->is_global_scope());
- CHECK_EQ(1, global_scope->inner_scopes()->length());
+ i::Scope* script_scope = info.function()->scope();
+ CHECK(script_scope->is_script_scope());
+ CHECK_EQ(1, script_scope->inner_scopes()->length());
- i::Scope* scope = global_scope->inner_scopes()->at(0);
+ i::Scope* scope = script_scope->inner_scopes()->at(0);
CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0,
scope->uses_arguments());
CHECK_EQ((source_data[i].expected & SUPER) != 0, scope->uses_super());
// Check scope types and positions.
i::Scope* scope = info.function()->scope();
- CHECK(scope->is_global_scope());
+ CHECK(scope->is_script_scope());
CHECK_EQ(scope->start_position(), 0);
CHECK_EQ(scope->end_position(), kProgramSize);
CHECK_EQ(scope->inner_scopes()->length(), 1);
const i::AstRawString* name = avf.GetOneByteString("result");
i::Handle<i::String> str = name->string();
CHECK(str->IsInternalizedString());
- i::Scope* global_scope =
- new (&zone) i::Scope(NULL, i::GLOBAL_SCOPE, &avf, &zone);
- global_scope->Initialize();
- i::Scope* s = i::Scope::DeserializeScopeChain(context, global_scope, &zone);
- DCHECK(s != global_scope);
+ i::Scope* script_scope =
+ new (&zone) i::Scope(NULL, i::SCRIPT_SCOPE, &avf, &zone);
+ script_scope->Initialize();
+ i::Scope* s = i::Scope::DeserializeScopeChain(context, script_scope, &zone);
+ DCHECK(s != script_scope);
DCHECK(name != NULL);
// Get result from h's function context (that is f's context)
i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
avf.Internalize(isolate);
- i::Scope* global_scope =
- new (&zone) i::Scope(NULL, i::GLOBAL_SCOPE, &avf, &zone);
- global_scope->Initialize();
- i::Scope* s = i::Scope::DeserializeScopeChain(context, global_scope, &zone);
- DCHECK(s != global_scope);
+ i::Scope* script_scope =
+ new (&zone) i::Scope(NULL, i::SCRIPT_SCOPE, &avf, &zone);
+ script_scope->Initialize();
+ i::Scope* s = i::Scope::DeserializeScopeChain(context, script_scope, &zone);
+ DCHECK(s != script_scope);
const i::AstRawString* name_x = avf.GetOneByteString("x");
// Get result from f's function context (that is g's outer context)
i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
avf.Internalize(isolate);
- i::Scope* global_scope =
- new (&zone) i::Scope(NULL, i::GLOBAL_SCOPE, &avf, &zone);
- global_scope->Initialize();
- i::Scope* s = i::Scope::DeserializeScopeChain(context, global_scope, &zone);
- DCHECK(s != global_scope);
+ i::Scope* script_scope =
+ new (&zone) i::Scope(NULL, i::SCRIPT_SCOPE, &avf, &zone);
+ script_scope->Initialize();
+ i::Scope* s = i::Scope::DeserializeScopeChain(context, script_scope, &zone);
+ DCHECK(s != script_scope);
const i::AstRawString* name_x = avf.GetOneByteString("x");
const i::AstRawString* name_f = avf.GetOneByteString("f");
const i::AstRawString* name_y = avf.GetOneByteString("y");
}
-TEST(Bug3628) {
+TEST(SerializeWithHarmonyScoping) {
FLAG_serialize_toplevel = true;
FLAG_harmony_scoping = true;
SHARED(CreateWithContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
SHARED(CreateBlockContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
SHARED(CreateModuleContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1),
- SHARED(CreateGlobalContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1)
+ SHARED(CreateScriptContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1)
#undef SHARED
};