Upgrade V8 to version 4.9.385.28
https://chromium.googlesource.com/v8/v8/+/4.9.385.28
FPIIM-449
Change-Id: I4b2e74289d4bf3667f2f3dc8aa2e541f63e26eb4
diff --git a/src/contexts.cc b/src/contexts.cc
index 57490a1..79a9e92 100644
--- a/src/contexts.cc
+++ b/src/contexts.cc
@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "src/v8.h"
+#include "src/contexts.h"
+#include "src/ast/scopeinfo.h"
#include "src/bootstrapper.h"
-#include "src/debug.h"
-#include "src/scopeinfo.h"
+#include "src/debug/debug.h"
+#include "src/isolate-inl.h"
namespace v8 {
namespace internal {
@@ -18,17 +19,20 @@
int used = table->used();
int length = table->length();
CHECK(used >= 0 && length > 0 && used < length);
- if (used + 1 == length) {
+ if (used + kFirstContextSlot == length) {
CHECK(length < Smi::kMaxValue / 2);
- result = Handle<ScriptContextTable>::cast(
- FixedArray::CopySize(table, length * 2));
+ Isolate* isolate = table->GetIsolate();
+ Handle<FixedArray> copy =
+ isolate->factory()->CopyFixedArrayAndGrow(table, length);
+ copy->set_map(isolate->heap()->script_context_table_map());
+ result = Handle<ScriptContextTable>::cast(copy);
} else {
result = table;
}
result->set_used(used + 1);
DCHECK(script_context->IsScriptContext());
- result->set(used + 1, *script_context);
+ result->set(used + kFirstContextSlot, *script_context);
return result;
}
@@ -38,7 +42,7 @@
for (int i = 0; i < table->used(); i++) {
Handle<Context> context = GetContext(table, i);
DCHECK(context->IsScriptContext());
- Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension()));
+ Handle<ScopeInfo> scope_info(context->scope_info());
int slot_index = ScopeInfo::ContextSlotIndex(
scope_info, name, &result->mode, &result->init_flag,
&result->maybe_assigned_flag);
@@ -53,10 +57,22 @@
}
+bool Context::is_declaration_context() {
+ if (IsFunctionContext() || IsNativeContext() || IsScriptContext()) {
+ return true;
+ }
+ if (!IsBlockContext()) return false;
+ Object* ext = extension();
+ // If we have the special extension, we immediately know it must be a
+ // declaration scope. That's just a small performance shortcut.
+ return ext->IsSloppyBlockWithEvalContextExtension()
+ || ScopeInfo::cast(ext)->is_declaration_scope();
+}
+
+
Context* Context::declaration_context() {
Context* current = this;
- while (!current->IsFunctionContext() && !current->IsNativeContext() &&
- !current->IsScriptContext()) {
+ while (!current->is_declaration_context()) {
current = current->previous();
DCHECK(current->closure() == closure());
}
@@ -64,14 +80,46 @@
}
-JSBuiltinsObject* Context::builtins() {
- GlobalObject* object = global_object();
- if (object->IsJSGlobalObject()) {
- return JSGlobalObject::cast(object)->builtins();
- } else {
- DCHECK(object->IsJSBuiltinsObject());
- return JSBuiltinsObject::cast(object);
+JSObject* Context::extension_object() {
+ DCHECK(IsNativeContext() || IsFunctionContext() || IsBlockContext());
+ HeapObject* object = extension();
+ if (object->IsTheHole()) return nullptr;
+ if (IsBlockContext()) {
+ if (!object->IsSloppyBlockWithEvalContextExtension()) return nullptr;
+ object = SloppyBlockWithEvalContextExtension::cast(object)->extension();
}
+ DCHECK(object->IsJSContextExtensionObject() ||
+ (IsNativeContext() && object->IsJSGlobalObject()));
+ return JSObject::cast(object);
+}
+
+
+JSReceiver* Context::extension_receiver() {
+ DCHECK(IsNativeContext() || IsWithContext() ||
+ IsFunctionContext() || IsBlockContext());
+ return IsWithContext() ? JSReceiver::cast(extension()) : extension_object();
+}
+
+
+ScopeInfo* Context::scope_info() {
+ DCHECK(IsModuleContext() || IsScriptContext() || IsBlockContext());
+ HeapObject* object = extension();
+ if (object->IsSloppyBlockWithEvalContextExtension()) {
+ DCHECK(IsBlockContext());
+ object = SloppyBlockWithEvalContextExtension::cast(object)->scope_info();
+ }
+ return ScopeInfo::cast(object);
+}
+
+
+String* Context::catch_name() {
+ DCHECK(IsCatchContext());
+ return String::cast(extension());
+}
+
+
+JSGlobalObject* Context::global_object() {
+ return JSGlobalObject::cast(native_context()->extension());
}
@@ -84,26 +132,6 @@
}
-Context* Context::native_context() {
- // Fast case: the global object for this context has been set. In
- // that case, the global object has a direct pointer to the global
- // context.
- if (global_object()->IsGlobalObject()) {
- return global_object()->native_context();
- }
-
- // During bootstrapping, the global object might not be set and we
- // have to search the context chain to find the native context.
- DCHECK(this->GetIsolate()->bootstrapper()->IsActive());
- Context* current = this;
- while (!current->IsNativeContext()) {
- JSFunction* closure = JSFunction::cast(current->closure());
- current = Context::cast(closure->context());
- }
- return current;
-}
-
-
JSObject* Context::global_proxy() {
return native_context()->global_proxy_object();
}
@@ -118,31 +146,24 @@
* Lookups a property in an object environment, taking the unscopables into
* account. This is used For HasBinding spec algorithms for ObjectEnvironment.
*/
-static Maybe<PropertyAttributes> UnscopableLookup(LookupIterator* it) {
+static Maybe<bool> UnscopableLookup(LookupIterator* it) {
Isolate* isolate = it->isolate();
- Maybe<PropertyAttributes> attrs = JSReceiver::GetPropertyAttributes(it);
- DCHECK(attrs.has_value || isolate->has_pending_exception());
- if (!attrs.has_value || attrs.value == ABSENT) return attrs;
+ Maybe<bool> found = JSReceiver::HasProperty(it);
+ if (!found.IsJust() || !found.FromJust()) return found;
- Handle<Symbol> unscopables_symbol = isolate->factory()->unscopables_symbol();
- Handle<Object> receiver = it->GetReceiver();
Handle<Object> unscopables;
- MaybeHandle<Object> maybe_unscopables =
- Object::GetProperty(receiver, unscopables_symbol);
- if (!maybe_unscopables.ToHandle(&unscopables)) {
- return Maybe<PropertyAttributes>();
- }
- if (!unscopables->IsSpecObject()) return attrs;
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(
+ isolate, unscopables,
+ Object::GetProperty(it->GetReceiver(),
+ isolate->factory()->unscopables_symbol()),
+ Nothing<bool>());
+ if (!unscopables->IsJSReceiver()) return Just(true);
Handle<Object> blacklist;
- MaybeHandle<Object> maybe_blacklist =
- Object::GetProperty(unscopables, it->name());
- if (!maybe_blacklist.ToHandle(&blacklist)) {
- DCHECK(isolate->has_pending_exception());
- return Maybe<PropertyAttributes>();
- }
- if (!blacklist->IsUndefined()) return maybe(ABSENT);
- return attrs;
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, blacklist,
+ Object::GetProperty(unscopables, it->name()),
+ Nothing<bool>());
+ return Just(!blacklist->BooleanValue());
}
static void GetAttributesAndBindingFlags(VariableMode mode,
@@ -150,7 +171,6 @@
PropertyAttributes* attributes,
BindingFlags* binding_flags) {
switch (mode) {
- case INTERNAL: // Fall through.
case VAR:
*attributes = NONE;
*binding_flags = MUTABLE_IS_INITIALIZED;
@@ -173,9 +193,9 @@
? IMMUTABLE_CHECK_INITIALIZED_HARMONY
: IMMUTABLE_IS_INITIALIZED_HARMONY;
break;
- case MODULE:
- *attributes = READ_ONLY;
- *binding_flags = IMMUTABLE_IS_INITIALIZED_HARMONY;
+ case IMPORT:
+ // TODO(ES6)
+ UNREACHABLE();
break;
case DYNAMIC:
case DYNAMIC_GLOBAL:
@@ -202,7 +222,7 @@
Handle<Context> context(this, isolate);
bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0;
- *index = -1;
+ *index = kNotFound;
*attributes = ABSENT;
*binding_flags = MISSING_BINDING;
@@ -220,13 +240,12 @@
PrintF("\n");
}
-
// 1. Check global objects, subjects of with, and extension objects.
- if (context->IsNativeContext() ||
- context->IsWithContext() ||
- (context->IsFunctionContext() && context->has_extension())) {
- Handle<JSReceiver> object(
- JSReceiver::cast(context->extension()), isolate);
+ if ((context->IsNativeContext() ||
+ (context->IsWithContext() && ((flags & SKIP_WITH_CONTEXT) == 0)) ||
+ context->IsFunctionContext() || context->IsBlockContext()) &&
+ context->extension_receiver() != nullptr) {
+ Handle<JSReceiver> object(context->extension_receiver());
if (context->IsNativeContext()) {
if (FLAG_trace_contexts) {
@@ -254,22 +273,35 @@
// 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.
- Maybe<PropertyAttributes> maybe;
+ Maybe<PropertyAttributes> maybe = Nothing<PropertyAttributes>();
if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
object->IsJSContextExtensionObject()) {
maybe = JSReceiver::GetOwnPropertyAttributes(object, name);
} else if (context->IsWithContext()) {
- LookupIterator it(object, name);
- maybe = UnscopableLookup(&it);
+ // A with context will never bind "this".
+ if (name->Equals(*isolate->factory()->this_string())) {
+ maybe = Just(ABSENT);
+ } else {
+ LookupIterator it(object, name);
+ Maybe<bool> found = UnscopableLookup(&it);
+ if (found.IsNothing()) {
+ maybe = Nothing<PropertyAttributes>();
+ } else {
+ // Luckily, consumers of |maybe| only care whether the property
+ // was absent or not, so we can return a dummy |NONE| value
+ // for its attributes when it was present.
+ maybe = Just(found.FromJust() ? NONE : ABSENT);
+ }
+ }
} else {
maybe = JSReceiver::GetPropertyAttributes(object, name);
}
- if (!maybe.has_value) return Handle<Object>();
+ if (!maybe.IsJust()) return Handle<Object>();
DCHECK(!isolate->has_pending_exception());
- *attributes = maybe.value;
+ *attributes = maybe.FromJust();
- if (maybe.value != ABSENT) {
+ if (maybe.FromJust() != ABSENT) {
if (FLAG_trace_contexts) {
PrintF("=> found property in context object %p\n",
reinterpret_cast<void*>(*object));
@@ -280,17 +312,12 @@
// 2. Check the context proper if it has slots.
if (context->IsFunctionContext() || context->IsBlockContext() ||
- (FLAG_harmony_scoping && context->IsScriptContext())) {
+ context->IsScriptContext()) {
// Use serialized scope information of functions and blocks to search
// for the context index.
- Handle<ScopeInfo> scope_info;
- if (context->IsFunctionContext()) {
- scope_info = Handle<ScopeInfo>(
- context->closure()->shared()->scope_info(), isolate);
- } else {
- scope_info = Handle<ScopeInfo>(
- ScopeInfo::cast(context->extension()), isolate);
- }
+ Handle<ScopeInfo> scope_info(context->IsFunctionContext()
+ ? context->closure()->shared()->scope_info()
+ : context->scope_info());
VariableMode mode;
InitializationFlag init_flag;
// TODO(sigurds) Figure out whether maybe_assigned_flag should
@@ -331,7 +358,7 @@
} else if (context->IsCatchContext()) {
// Catch contexts have the variable name in the extension slot.
- if (String::Equals(name, handle(String::cast(context->extension())))) {
+ if (String::Equals(name, handle(context->catch_name()))) {
if (FLAG_trace_contexts) {
PrintF("=> found in catch context\n");
}
@@ -343,7 +370,9 @@
}
// 3. Prepare to continue with the previous (next outermost) context.
- if (context->IsNativeContext()) {
+ if (context->IsNativeContext() ||
+ ((flags & STOP_AT_DECLARATION_SCOPE) != 0 &&
+ context->is_declaration_context())) {
follow_context_chain = false;
} else {
context = Handle<Context>(context->previous(), isolate);
@@ -357,6 +386,25 @@
}
+void Context::InitializeGlobalSlots() {
+ DCHECK(IsScriptContext());
+ DisallowHeapAllocation no_gc;
+
+ ScopeInfo* scope_info = this->scope_info();
+
+ int context_globals = scope_info->ContextGlobalCount();
+ if (context_globals > 0) {
+ PropertyCell* empty_cell = GetHeap()->empty_property_cell();
+
+ int context_locals = scope_info->ContextLocalCount();
+ int index = Context::MIN_CONTEXT_SLOTS + context_locals;
+ for (int i = 0; i < context_globals; i++) {
+ set(index++, empty_cell);
+ }
+ }
+}
+
+
void Context::AddOptimizedFunction(JSFunction* function) {
DCHECK(IsNativeContext());
#ifdef ENABLE_SLOW_DCHECKS
@@ -390,8 +438,9 @@
DCHECK(function->next_function_link()->IsUndefined());
- function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST));
- set(OPTIMIZED_FUNCTIONS_LIST, function);
+ function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST),
+ UPDATE_WEAK_WRITE_BARRIER);
+ set(OPTIMIZED_FUNCTIONS_LIST, function, UPDATE_WEAK_WRITE_BARRIER);
}
@@ -405,11 +454,14 @@
element_function->next_function_link()->IsJSFunction());
if (element_function == function) {
if (prev == NULL) {
- set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link());
+ set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link(),
+ UPDATE_WEAK_WRITE_BARRIER);
} else {
- prev->set_next_function_link(element_function->next_function_link());
+ prev->set_next_function_link(element_function->next_function_link(),
+ UPDATE_WEAK_WRITE_BARRIER);
}
- element_function->set_next_function_link(GetHeap()->undefined_value());
+ element_function->set_next_function_link(GetHeap()->undefined_value(),
+ UPDATE_WEAK_WRITE_BARRIER);
return;
}
prev = element_function;
@@ -421,7 +473,7 @@
void Context::SetOptimizedFunctionsListHead(Object* head) {
DCHECK(IsNativeContext());
- set(OPTIMIZED_FUNCTIONS_LIST, head);
+ set(OPTIMIZED_FUNCTIONS_LIST, head, UPDATE_WEAK_WRITE_BARRIER);
}
@@ -436,13 +488,13 @@
DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION);
DCHECK(code->next_code_link()->IsUndefined());
code->set_next_code_link(get(OPTIMIZED_CODE_LIST));
- set(OPTIMIZED_CODE_LIST, code);
+ set(OPTIMIZED_CODE_LIST, code, UPDATE_WEAK_WRITE_BARRIER);
}
void Context::SetOptimizedCodeListHead(Object* head) {
DCHECK(IsNativeContext());
- set(OPTIMIZED_CODE_LIST, head);
+ set(OPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER);
}
@@ -454,7 +506,7 @@
void Context::SetDeoptimizedCodeListHead(Object* head) {
DCHECK(IsNativeContext());
- set(DEOPTIMIZED_CODE_LIST, head);
+ set(DEOPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER);
}
@@ -473,7 +525,43 @@
}
+#define COMPARE_NAME(index, type, name) \
+ if (string->IsOneByteEqualTo(STATIC_CHAR_VECTOR(#name))) return index;
+
+int Context::ImportedFieldIndexForName(Handle<String> string) {
+ NATIVE_CONTEXT_IMPORTED_FIELDS(COMPARE_NAME)
+ return kNotFound;
+}
+
+
+int Context::IntrinsicIndexForName(Handle<String> string) {
+ NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(COMPARE_NAME);
+ return kNotFound;
+}
+
+#undef COMPARE_NAME
+
+
+bool Context::IsJSBuiltin(Handle<Context> native_context,
+ Handle<JSFunction> function) {
+#define COMPARE_FUNCTION(index, type, name) \
+ if (*function == native_context->get(index)) return true;
+ NATIVE_CONTEXT_JS_BUILTINS(COMPARE_FUNCTION);
+#undef COMPARE_FUNCTION
+ return false;
+}
+
+
#ifdef DEBUG
+
+bool Context::IsBootstrappingOrNativeContext(Isolate* isolate, Object* object) {
+ // During bootstrapping we allow all objects to pass as global
+ // objects. This is necessary to fix circular dependencies.
+ return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
+ isolate->bootstrapper()->IsActive() || object->IsNativeContext();
+}
+
+
bool Context::IsBootstrappingOrValidParentContext(
Object* object, Context* child) {
// During bootstrapping we allow all objects to pass as
@@ -485,14 +573,18 @@
context->IsModuleContext() || !child->IsModuleContext();
}
-
-bool Context::IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object) {
- // During bootstrapping we allow all objects to pass as global
- // objects. This is necessary to fix circular dependencies.
- return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
- isolate->bootstrapper()->IsActive() ||
- object->IsGlobalObject();
-}
#endif
-} } // namespace v8::internal
+
+void Context::IncrementErrorsThrown() {
+ DCHECK(IsNativeContext());
+
+ int previous_value = errors_thrown()->value();
+ set_errors_thrown(Smi::FromInt(previous_value + 1));
+}
+
+
+int Context::GetErrorsThrown() { return errors_thrown()->value(); }
+
+} // namespace internal
+} // namespace v8