Roll V8 back to 3.6
Roll back to V8 3.6 to fix x86 build, we don't have ucontext.h.
This reverts commits:
5d4cdbf7a67d3662fa0bee4efdb7edd8daec9b0b
c7cc028aaeedbbfa11c11d0b7b243b3d9e837ed9
592a9fc1d8ea420377a2e7efd0600e20b058be2b
Bug: 5688872
Change-Id: Ic961bb5e65b778e98bbfb71cce71d99fa949e995
diff --git a/src/contexts.cc b/src/contexts.cc
index 76784bd..4f93abd 100644
--- a/src/contexts.cc
+++ b/src/contexts.cc
@@ -86,14 +86,14 @@
Handle<Object> Context::Lookup(Handle<String> name,
ContextLookupFlags flags,
- int* index,
+ int* index_,
PropertyAttributes* attributes,
BindingFlags* binding_flags) {
Isolate* isolate = GetIsolate();
Handle<Context> context(this, isolate);
bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0;
- *index = -1;
+ *index_ = -1;
*attributes = ABSENT;
*binding_flags = MISSING_BINDING;
@@ -110,51 +110,70 @@
PrintF("\n");
}
- // 1. Check global objects, subjects of with, and extension objects.
- if (context->IsGlobalContext() ||
- context->IsWithContext() ||
- (context->IsFunctionContext() && context->has_extension())) {
- Handle<JSObject> object(JSObject::cast(context->extension()), isolate);
- // Context extension objects needs to behave as if they have no
- // prototype. So even if we want to follow prototype chains, we need
- // to only do a local lookup for context extension objects.
- if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
- object->IsJSContextExtensionObject()) {
- *attributes = object->GetLocalPropertyAttribute(*name);
- } else {
- *attributes = object->GetPropertyAttribute(*name);
- }
- if (*attributes != ABSENT) {
- if (FLAG_trace_contexts) {
- PrintF("=> found property in context object %p\n",
- reinterpret_cast<void*>(*object));
+ // Check extension/with/global object.
+ if (!context->IsBlockContext() && context->has_extension()) {
+ if (context->IsCatchContext()) {
+ // Catch contexts have the variable name in the extension slot.
+ if (name->Equals(String::cast(context->extension()))) {
+ if (FLAG_trace_contexts) {
+ PrintF("=> found in catch context\n");
+ }
+ *index_ = Context::THROWN_OBJECT_INDEX;
+ *attributes = NONE;
+ *binding_flags = MUTABLE_IS_INITIALIZED;
+ return context;
}
- return object;
+ } else {
+ ASSERT(context->IsGlobalContext() ||
+ context->IsFunctionContext() ||
+ context->IsWithContext());
+ // Global, function, and with contexts may have an object in the
+ // extension slot.
+ Handle<JSObject> extension(JSObject::cast(context->extension()),
+ isolate);
+ // Context extension objects needs to behave as if they have no
+ // prototype. So even if we want to follow prototype chains, we
+ // need to only do a local lookup for context extension objects.
+ if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
+ extension->IsJSContextExtensionObject()) {
+ *attributes = extension->GetLocalPropertyAttribute(*name);
+ } else {
+ *attributes = extension->GetPropertyAttribute(*name);
+ }
+ if (*attributes != ABSENT) {
+ // property found
+ if (FLAG_trace_contexts) {
+ PrintF("=> found property in context object %p\n",
+ reinterpret_cast<void*>(*extension));
+ }
+ return extension;
+ }
}
}
- // 2. Check the context proper if it has slots.
+ // Check serialized scope information of functions and blocks. Only
+ // functions can have parameters, and a function name.
if (context->IsFunctionContext() || context->IsBlockContext()) {
- // Use serialized scope information of functions and blocks to search
- // for the context index.
- Handle<ScopeInfo> scope_info;
+ // We may have context-local slots. Check locals in the context.
+ Handle<SerializedScopeInfo> scope_info;
if (context->IsFunctionContext()) {
- scope_info = Handle<ScopeInfo>(
+ scope_info = Handle<SerializedScopeInfo>(
context->closure()->shared()->scope_info(), isolate);
} else {
- scope_info = Handle<ScopeInfo>(
- ScopeInfo::cast(context->extension()), isolate);
+ ASSERT(context->IsBlockContext());
+ scope_info = Handle<SerializedScopeInfo>(
+ SerializedScopeInfo::cast(context->extension()), isolate);
}
- VariableMode mode;
- InitializationFlag init_flag;
- int slot_index = scope_info->ContextSlotIndex(*name, &mode, &init_flag);
- ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS);
- if (slot_index >= 0) {
+
+ Variable::Mode mode;
+ int index = scope_info->ContextSlotIndex(*name, &mode);
+ ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
+ if (index >= 0) {
if (FLAG_trace_contexts) {
PrintF("=> found local in context slot %d (mode = %d)\n",
- slot_index, mode);
+ index, mode);
}
- *index = slot_index;
+ *index_ = index;
// Note: Fixed context slots are statically allocated by the compiler.
// Statically allocated variables always have a statically known mode,
// which is the mode with which they were declared when added to the
@@ -162,31 +181,23 @@
// declared variables that were introduced through declaration nodes)
// must not appear here.
switch (mode) {
- case INTERNAL: // Fall through.
- case VAR:
+ case Variable::INTERNAL: // Fall through.
+ case Variable::VAR:
*attributes = NONE;
*binding_flags = MUTABLE_IS_INITIALIZED;
break;
- case LET:
+ case Variable::LET:
*attributes = NONE;
- *binding_flags = (init_flag == kNeedsInitialization)
- ? MUTABLE_CHECK_INITIALIZED : MUTABLE_IS_INITIALIZED;
+ *binding_flags = MUTABLE_CHECK_INITIALIZED;
break;
- case CONST:
+ case Variable::CONST:
*attributes = READ_ONLY;
- *binding_flags = (init_flag == kNeedsInitialization)
- ? IMMUTABLE_CHECK_INITIALIZED : IMMUTABLE_IS_INITIALIZED;
+ *binding_flags = IMMUTABLE_CHECK_INITIALIZED;
break;
- case CONST_HARMONY:
- *attributes = READ_ONLY;
- *binding_flags = (init_flag == kNeedsInitialization)
- ? IMMUTABLE_CHECK_INITIALIZED_HARMONY :
- IMMUTABLE_IS_INITIALIZED_HARMONY;
- break;
- case DYNAMIC:
- case DYNAMIC_GLOBAL:
- case DYNAMIC_LOCAL:
- case TEMPORARY:
+ case Variable::DYNAMIC:
+ case Variable::DYNAMIC_GLOBAL:
+ case Variable::DYNAMIC_LOCAL:
+ case Variable::TEMPORARY:
UNREACHABLE();
break;
}
@@ -195,37 +206,22 @@
// Check the slot corresponding to the intermediate context holding
// only the function name variable.
- if (follow_context_chain && context->IsFunctionContext()) {
- VariableMode mode;
- int function_index = scope_info->FunctionContextSlotIndex(*name, &mode);
- if (function_index >= 0) {
+ if (follow_context_chain) {
+ int index = scope_info->FunctionContextSlotIndex(*name);
+ if (index >= 0) {
if (FLAG_trace_contexts) {
PrintF("=> found intermediate function in context slot %d\n",
- function_index);
+ index);
}
- *index = function_index;
+ *index_ = index;
*attributes = READ_ONLY;
- ASSERT(mode == CONST || mode == CONST_HARMONY);
- *binding_flags = (mode == CONST)
- ? IMMUTABLE_IS_INITIALIZED : IMMUTABLE_IS_INITIALIZED_HARMONY;
+ *binding_flags = IMMUTABLE_IS_INITIALIZED;
return context;
}
}
-
- } else if (context->IsCatchContext()) {
- // Catch contexts have the variable name in the extension slot.
- if (name->Equals(String::cast(context->extension()))) {
- if (FLAG_trace_contexts) {
- PrintF("=> found in catch context\n");
- }
- *index = Context::THROWN_OBJECT_INDEX;
- *attributes = NONE;
- *binding_flags = MUTABLE_IS_INITIALIZED;
- return context;
- }
}
- // 3. Prepare to continue with the previous (next outermost) context.
+ // Proceed with the previous context.
if (context->IsGlobalContext()) {
follow_context_chain = false;
} else {
@@ -240,6 +236,68 @@
}
+bool Context::GlobalIfNotShadowedByEval(Handle<String> name) {
+ Context* context = this;
+
+ // Check that there is no local with the given name in contexts
+ // before the global context and check that there are no context
+ // extension objects (conservative check for with statements).
+ while (!context->IsGlobalContext()) {
+ // Check if the context is a catch or with context, or has introduced
+ // bindings by calling non-strict eval.
+ if (context->has_extension()) return false;
+
+ // Not a with context so it must be a function context.
+ ASSERT(context->IsFunctionContext());
+
+ // Check non-parameter locals.
+ Handle<SerializedScopeInfo> scope_info(
+ context->closure()->shared()->scope_info());
+ Variable::Mode mode;
+ int index = scope_info->ContextSlotIndex(*name, &mode);
+ ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
+ if (index >= 0) return false;
+
+ // Check parameter locals.
+ int param_index = scope_info->ParameterIndex(*name);
+ if (param_index >= 0) return false;
+
+ // Check context only holding the function name variable.
+ index = scope_info->FunctionContextSlotIndex(*name);
+ if (index >= 0) return false;
+ context = context->previous();
+ }
+
+ // No local or potential with statement found so the variable is
+ // global unless it is shadowed by an eval-introduced variable.
+ return true;
+}
+
+
+void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_eval,
+ bool* outer_scope_calls_non_strict_eval) {
+ // Skip up the context chain checking all the function contexts to see
+ // whether they call eval.
+ Context* context = this;
+ while (!context->IsGlobalContext()) {
+ if (context->IsFunctionContext()) {
+ Handle<SerializedScopeInfo> scope_info(
+ context->closure()->shared()->scope_info());
+ if (scope_info->CallsEval()) {
+ *outer_scope_calls_eval = true;
+ if (!scope_info->IsStrictMode()) {
+ // No need to go further since the answers will not change from
+ // here.
+ *outer_scope_calls_non_strict_eval = true;
+ return;
+ }
+ }
+ }
+ context = context->previous();
+ }
+}
+
+
void Context::AddOptimizedFunction(JSFunction* function) {
ASSERT(IsGlobalContext());
#ifdef DEBUG