summaryrefslogtreecommitdiff
path: root/deps/v8/src/runtime/runtime-internal.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/runtime/runtime-internal.cc')
-rw-r--r--deps/v8/src/runtime/runtime-internal.cc213
1 files changed, 124 insertions, 89 deletions
diff --git a/deps/v8/src/runtime/runtime-internal.cc b/deps/v8/src/runtime/runtime-internal.cc
index 8c227a1703..f8a7d5ba83 100644
--- a/deps/v8/src/runtime/runtime-internal.cc
+++ b/deps/v8/src/runtime/runtime-internal.cc
@@ -6,15 +6,18 @@
#include "src/api.h"
#include "src/arguments-inl.h"
+#include "src/ast/ast-traversal-visitor.h"
#include "src/ast/prettyprinter.h"
#include "src/bootstrapper.h"
#include "src/builtins/builtins.h"
#include "src/conversions.h"
+#include "src/counters.h"
#include "src/debug/debug.h"
#include "src/frames-inl.h"
#include "src/isolate-inl.h"
-#include "src/messages.h"
+#include "src/message-template.h"
#include "src/objects/js-array-inl.h"
+#include "src/ostreams.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/parsing.h"
#include "src/runtime/runtime-utils.h"
@@ -31,40 +34,18 @@ RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
return ReadOnlyRoots(isolate).undefined_value();
}
-RUNTIME_FUNCTION(Runtime_ExportFromRuntime) {
+RUNTIME_FUNCTION(Runtime_FatalProcessOutOfMemoryInAllocateRaw) {
HandleScope scope(isolate);
- DCHECK_EQ(1, args.length());
- CONVERT_ARG_HANDLE_CHECKED(JSObject, container, 0);
- CHECK(isolate->bootstrapper()->IsActive());
- JSObject::NormalizeProperties(container, KEEP_INOBJECT_PROPERTIES, 10,
- "ExportFromRuntime");
- Bootstrapper::ExportFromRuntime(isolate, container);
- JSObject::MigrateSlowToFast(container, 0, "ExportFromRuntime");
- return *container;
+ DCHECK_EQ(0, args.length());
+ isolate->heap()->FatalProcessOutOfMemory("CodeStubAssembler::AllocateRaw");
+ UNREACHABLE();
}
-RUNTIME_FUNCTION(Runtime_InstallToContext) {
+RUNTIME_FUNCTION(Runtime_FatalProcessOutOfMemoryInvalidArrayLength) {
HandleScope scope(isolate);
- DCHECK_EQ(1, args.length());
- CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
- CHECK(array->HasFastElements());
- CHECK(isolate->bootstrapper()->IsActive());
- Handle<Context> native_context = isolate->native_context();
- Handle<FixedArray> fixed_array(FixedArray::cast(array->elements()), isolate);
- int length = Smi::ToInt(array->length());
- for (int i = 0; i < length; i += 2) {
- CHECK(fixed_array->get(i)->IsString());
- Handle<String> name(String::cast(fixed_array->get(i)), isolate);
- CHECK(fixed_array->get(i + 1)->IsJSObject());
- Handle<JSObject> object(JSObject::cast(fixed_array->get(i + 1)), isolate);
- int index = Context::ImportedFieldIndexForName(name);
- if (index == Context::kNotFound) {
- index = Context::IntrinsicIndexForName(name);
- }
- CHECK_NE(index, Context::kNotFound);
- native_context->set(index, *object);
- }
- return ReadOnlyRoots(isolate).undefined_value();
+ DCHECK_EQ(0, args.length());
+ isolate->heap()->FatalProcessOutOfMemory("invalid array length");
+ UNREACHABLE();
}
RUNTIME_FUNCTION(Runtime_Throw) {
@@ -92,19 +73,18 @@ RUNTIME_FUNCTION(Runtime_ThrowSymbolAsyncIteratorInvalid) {
isolate, NewTypeError(MessageTemplate::kSymbolAsyncIteratorInvalid));
}
-#define THROW_ERROR(isolate, args, call) \
- HandleScope scope(isolate); \
- DCHECK_LE(1, args.length()); \
- CONVERT_SMI_ARG_CHECKED(message_id_smi, 0); \
- \
- Handle<Object> undefined = isolate->factory()->undefined_value(); \
- Handle<Object> arg0 = (args.length() > 1) ? args.at(1) : undefined; \
- Handle<Object> arg1 = (args.length() > 2) ? args.at(2) : undefined; \
- Handle<Object> arg2 = (args.length() > 3) ? args.at(3) : undefined; \
- \
- MessageTemplate::Template message_id = \
- static_cast<MessageTemplate::Template>(message_id_smi); \
- \
+#define THROW_ERROR(isolate, args, call) \
+ HandleScope scope(isolate); \
+ DCHECK_LE(1, args.length()); \
+ CONVERT_SMI_ARG_CHECKED(message_id_smi, 0); \
+ \
+ Handle<Object> undefined = isolate->factory()->undefined_value(); \
+ Handle<Object> arg0 = (args.length() > 1) ? args.at(1) : undefined; \
+ Handle<Object> arg1 = (args.length() > 2) ? args.at(2) : undefined; \
+ Handle<Object> arg2 = (args.length() > 3) ? args.at(3) : undefined; \
+ \
+ MessageTemplate message_id = MessageTemplateFromInt(message_id_smi); \
+ \
THROW_NEW_ERROR_RETURN_FAILURE(isolate, call(message_id, arg0, arg1, arg2));
RUNTIME_FUNCTION(Runtime_ThrowRangeError) {
@@ -182,8 +162,7 @@ RUNTIME_FUNCTION(Runtime_NewTypeError) {
DCHECK_EQ(2, args.length());
CONVERT_INT32_ARG_CHECKED(template_index, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
- auto message_template =
- static_cast<MessageTemplate::Template>(template_index);
+ MessageTemplate message_template = MessageTemplateFromInt(template_index);
return *isolate->factory()->NewTypeError(message_template, arg0);
}
@@ -192,8 +171,7 @@ RUNTIME_FUNCTION(Runtime_NewReferenceError) {
DCHECK_EQ(2, args.length());
CONVERT_INT32_ARG_CHECKED(template_index, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
- auto message_template =
- static_cast<MessageTemplate::Template>(template_index);
+ MessageTemplate message_template = MessageTemplateFromInt(template_index);
return *isolate->factory()->NewReferenceError(message_template, arg0);
}
@@ -202,8 +180,7 @@ RUNTIME_FUNCTION(Runtime_NewSyntaxError) {
DCHECK_EQ(2, args.length());
CONVERT_INT32_ARG_CHECKED(template_index, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
- auto message_template =
- static_cast<MessageTemplate::Template>(template_index);
+ MessageTemplate message_template = MessageTemplateFromInt(template_index);
return *isolate->factory()->NewSyntaxError(message_template, arg0);
}
@@ -275,7 +252,7 @@ RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_SMI_ARG_CHECKED(size, 0);
- CHECK(IsAligned(size, kPointerSize));
+ CHECK(IsAligned(size, kTaggedSize));
CHECK_GT(size, 0);
CHECK_LE(size, kMaxRegularHeapObjectSize);
return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE);
@@ -286,7 +263,7 @@ RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) {
DCHECK_EQ(2, args.length());
CONVERT_SMI_ARG_CHECKED(size, 0);
CONVERT_SMI_ARG_CHECKED(flags, 1);
- CHECK(IsAligned(size, kPointerSize));
+ CHECK(IsAligned(size, kTaggedSize));
CHECK_GT(size, 0);
bool double_align = AllocateDoubleAlignFlag::decode(flags);
AllocationSpace space = AllocateTargetSpace::decode(flags);
@@ -316,10 +293,6 @@ RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) {
return *result;
}
-RUNTIME_FUNCTION(Runtime_IS_VAR) {
- UNREACHABLE(); // implemented as macro in the parser
-}
-
namespace {
bool ComputeLocation(Isolate* isolate, MessageLocation* target) {
@@ -387,8 +360,8 @@ Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object,
return BuildDefaultCallSite(isolate, object);
}
-MessageTemplate::Template UpdateErrorTemplate(
- CallPrinter::ErrorHint hint, MessageTemplate::Template default_id) {
+MessageTemplate UpdateErrorTemplate(CallPrinter::ErrorHint hint,
+ MessageTemplate default_id) {
switch (hint) {
case CallPrinter::ErrorHint::kNormalIterator:
return MessageTemplate::kNotIterable;
@@ -414,7 +387,7 @@ MaybeHandle<Object> Runtime::ThrowIteratorError(Isolate* isolate,
Handle<Object> object) {
CallPrinter::ErrorHint hint = CallPrinter::kNone;
Handle<String> callsite = RenderCallSite(isolate, object, &hint);
- MessageTemplate::Template id = MessageTemplate::kNotIterableNoSymbolLoad;
+ MessageTemplate id = MessageTemplate::kNotIterableNoSymbolLoad;
if (hint == CallPrinter::kNone) {
Handle<Symbol> iterator_symbol = isolate->factory()->iterator_symbol();
@@ -440,7 +413,7 @@ RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) {
CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
CallPrinter::ErrorHint hint = CallPrinter::kNone;
Handle<String> callsite = RenderCallSite(isolate, object, &hint);
- MessageTemplate::Template id = MessageTemplate::kCalledNonCallable;
+ MessageTemplate id = MessageTemplate::kCalledNonCallable;
id = UpdateErrorTemplate(hint, id);
THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
}
@@ -451,10 +424,98 @@ RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) {
CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
CallPrinter::ErrorHint hint = CallPrinter::kNone;
Handle<String> callsite = RenderCallSite(isolate, object, &hint);
- MessageTemplate::Template id = MessageTemplate::kNotConstructor;
+ MessageTemplate id = MessageTemplate::kNotConstructor;
THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
}
+namespace {
+
+// Helper visitor for ThrowPatternAssignmentNonCoercible which finds an
+// object literal (representing a destructuring assignment) at a given source
+// position.
+class PatternFinder final : public AstTraversalVisitor<PatternFinder> {
+ public:
+ PatternFinder(Isolate* isolate, Expression* root, int position)
+ : AstTraversalVisitor(isolate, root),
+ position_(position),
+ object_literal_(nullptr) {}
+
+ ObjectLiteral* object_literal() const { return object_literal_; }
+
+ private:
+ // This is required so that the overriden Visit* methods can be
+ // called by the base class (template).
+ friend class AstTraversalVisitor<PatternFinder>;
+
+ void VisitObjectLiteral(ObjectLiteral* lit) {
+ // TODO(leszeks): This could be smarter in only traversing object literals
+ // that are known to be a destructuring pattern. We could then also
+ // potentially find the corresponding assignment value and report that too.
+ if (lit->position() == position_) {
+ object_literal_ = lit;
+ return;
+ }
+ AstTraversalVisitor::VisitObjectLiteral(lit);
+ }
+
+ int position_;
+ ObjectLiteral* object_literal_;
+};
+
+} // namespace
+
+RUNTIME_FUNCTION(Runtime_ThrowPatternAssignmentNonCoercible) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(0, args.length());
+
+ // Find the object literal representing the destructuring assignment, so that
+ // we can try to attribute the error to a property name on it rather than to
+ // the literal itself.
+ MaybeHandle<String> maybe_property_name;
+ MessageLocation location;
+ if (ComputeLocation(isolate, &location)) {
+ ParseInfo info(isolate, location.shared());
+ if (parsing::ParseAny(&info, location.shared(), isolate)) {
+ info.ast_value_factory()->Internalize(isolate);
+
+ PatternFinder finder(isolate, info.literal(), location.start_pos());
+ finder.Run();
+ if (finder.object_literal()) {
+ for (ObjectLiteralProperty* pattern_property :
+ *finder.object_literal()->properties()) {
+ Expression* key = pattern_property->key();
+ if (key->IsPropertyName()) {
+ int pos = key->position();
+ maybe_property_name =
+ key->AsLiteral()->AsRawPropertyName()->string();
+ // Change the message location to point at the property name.
+ location = MessageLocation(location.script(), pos, pos + 1,
+ location.shared());
+ break;
+ }
+ }
+ }
+ } else {
+ isolate->clear_pending_exception();
+ }
+ }
+
+ // Create a "non-coercible" type error with a property name if one is
+ // available, otherwise create a generic one.
+ Handle<Object> error;
+ Handle<String> property_name;
+ if (maybe_property_name.ToHandle(&property_name)) {
+ error = isolate->factory()->NewTypeError(
+ MessageTemplate::kNonCoercibleWithProperty, property_name);
+ } else {
+ error = isolate->factory()->NewTypeError(MessageTemplate::kNonCoercible);
+ }
+
+ // Explicitly pass the calculated location, as we may have updated it to match
+ // the property name.
+ return isolate->Throw(*error, &location);
+}
+
RUNTIME_FUNCTION(Runtime_ThrowConstructorReturnedNonObject) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
@@ -473,33 +534,6 @@ RUNTIME_FUNCTION(Runtime_CreateListFromArrayLike) {
isolate, object, ElementTypes::kAll));
}
-RUNTIME_FUNCTION(Runtime_DeserializeLazy) {
- HandleScope scope(isolate);
- DCHECK_EQ(1, args.length());
- CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
-
- DCHECK(FLAG_lazy_deserialization);
-
- Handle<SharedFunctionInfo> shared(function->shared(), isolate);
-
-#ifdef DEBUG
- int builtin_id = shared->builtin_id();
- // At this point, the builtins table should definitely have DeserializeLazy
- // set at the position of the target builtin.
- CHECK_EQ(Builtins::kDeserializeLazy,
- isolate->builtins()->builtin(builtin_id)->builtin_index());
- // The DeserializeLazy builtin tail-calls the deserialized builtin. This only
- // works with JS-linkage.
- CHECK(Builtins::IsLazy(builtin_id));
- CHECK_EQ(Builtins::TFJ, Builtins::KindOf(builtin_id));
-#endif // DEBUG
-
- Code* code = Snapshot::EnsureBuiltinIsDeserialized(isolate, shared);
-
- function->set_code(code);
- return code;
-}
-
RUNTIME_FUNCTION(Runtime_IncrementUseCounter) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
@@ -531,7 +565,8 @@ RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
if (args[0]->IsString()) {
// With a string argument, the results are appended to that file.
CONVERT_ARG_HANDLE_CHECKED(String, arg0, 0);
- String::FlatContent flat = arg0->GetFlatContent();
+ DisallowHeapAllocation no_gc;
+ String::FlatContent flat = arg0->GetFlatContent(no_gc);
const char* filename =
reinterpret_cast<const char*>(&(flat.ToOneByteVector()[0]));
f = std::fopen(filename, "a");