From 0e830ad0bb745c50a8019ce312dabba8c42d86c8 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Thu, 30 Oct 2014 14:21:27 +0000 Subject: [PATCH] Do not embed array objects in unoptimized code. R=verwaest@chromium.org Review URL: https://codereview.chromium.org/685393002 Cr-Commit-Position: refs/heads/master@{#25019} git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25019 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/ast-value-factory.cc | 30 ---------------- src/ast-value-factory.h | 59 +++++++++++++++----------------- src/ast.h | 7 ---- src/messages.js | 17 +++++++++ src/parser.cc | 10 ++---- test/mjsunit/serialize-embedded-error.js | 13 +++++++ 6 files changed, 59 insertions(+), 77 deletions(-) create mode 100644 test/mjsunit/serialize-embedded-error.js diff --git a/src/ast-value-factory.cc b/src/ast-value-factory.cc index 0a1949a..895ce39 100644 --- a/src/ast-value-factory.cc +++ b/src/ast-value-factory.cc @@ -159,9 +159,6 @@ bool AstValue::BooleanValue() const { return DoubleToBoolean(number_); case SMI: return smi_ != 0; - case STRING_ARRAY: - UNREACHABLE(); - break; case BOOLEAN: return bool_; case NULL_TYPE: @@ -202,22 +199,6 @@ void AstValue::Internalize(Isolate* isolate) { value_ = isolate->factory()->false_value(); } break; - case STRING_ARRAY: { - DCHECK(strings_ != NULL); - Factory* factory = isolate->factory(); - int len = strings_->length(); - Handle elements = factory->NewFixedArray(len, TENURED); - for (int i = 0; i < len; i++) { - const AstRawString* string = (*strings_)[i]; - Handle element = string->string(); - // Strings are already internalized. - DCHECK(!element.is_null()); - elements->set(i, *element); - } - value_ = - factory->NewJSArrayWithElements(elements, FAST_ELEMENTS, TENURED); - break; - } case NULL_TYPE: value_ = isolate->factory()->null_value(); break; @@ -350,17 +331,6 @@ const AstValue* AstValueFactory::NewBoolean(bool b) { } -const AstValue* AstValueFactory::NewStringList( - ZoneList* strings) { - AstValue* value = new (zone_) AstValue(strings); - if (isolate_) { - value->Internalize(isolate_); - } - values_.Add(value); - return value; -} - - const AstValue* AstValueFactory::NewNull() { GENERATE_VALUE_GETTER(null_value_, AstValue::NULL_TYPE); } diff --git a/src/ast-value-factory.h b/src/ast-value-factory.h index 774e534..071ca9c 100644 --- a/src/ast-value-factory.h +++ b/src/ast-value-factory.h @@ -194,7 +194,6 @@ class AstValue : public ZoneObject { NUMBER, SMI, BOOLEAN, - STRING_ARRAY, NULL_TYPE, UNDEFINED, THE_HOLE @@ -213,10 +212,6 @@ class AstValue : public ZoneObject { explicit AstValue(bool b) : type_(BOOLEAN) { bool_ = b; } - explicit AstValue(ZoneList* s) : type_(STRING_ARRAY) { - strings_ = s; - } - explicit AstValue(Type t) : type_(t) { DCHECK(t == NULL_TYPE || t == UNDEFINED || t == THE_HOLE); } @@ -239,33 +234,33 @@ class AstValue : public ZoneObject { // For generating constants. -#define STRING_CONSTANTS(F) \ - F(anonymous_function, "(anonymous function)") \ - F(arguments, "arguments") \ - F(constructor, "constructor") \ - F(done, "done") \ - F(dot, ".") \ - F(dot_for, ".for") \ - F(dot_generator, ".generator") \ - F(dot_generator_object, ".generator_object") \ - F(dot_iterator, ".iterator") \ - F(dot_module, ".module") \ - F(dot_result, ".result") \ - F(empty, "") \ - F(eval, "eval") \ - F(initialize_const_global, "initializeConstGlobal") \ - F(initialize_var_global, "initializeVarGlobal") \ - F(make_reference_error, "MakeReferenceError") \ - F(make_syntax_error, "MakeSyntaxError") \ - F(make_type_error, "MakeTypeError") \ - F(module, "module") \ - F(native, "native") \ - F(next, "next") \ - F(proto, "__proto__") \ - F(prototype, "prototype") \ - F(this, "this") \ - F(use_asm, "use asm") \ - F(use_strict, "use strict") \ +#define STRING_CONSTANTS(F) \ + F(anonymous_function, "(anonymous function)") \ + F(arguments, "arguments") \ + F(constructor, "constructor") \ + F(done, "done") \ + F(dot, ".") \ + F(dot_for, ".for") \ + F(dot_generator, ".generator") \ + F(dot_generator_object, ".generator_object") \ + F(dot_iterator, ".iterator") \ + F(dot_module, ".module") \ + F(dot_result, ".result") \ + F(empty, "") \ + F(eval, "eval") \ + F(initialize_const_global, "initializeConstGlobal") \ + F(initialize_var_global, "initializeVarGlobal") \ + F(make_reference_error, "MakeReferenceErrorEmbedded") \ + F(make_syntax_error, "MakeSyntaxErrorEmbedded") \ + F(make_type_error, "MakeTypeErrorEmbedded") \ + F(module, "module") \ + F(native, "native") \ + F(next, "next") \ + F(proto, "__proto__") \ + F(prototype, "prototype") \ + F(this, "this") \ + F(use_asm, "use asm") \ + F(use_strict, "use strict") \ F(value, "value") #define OTHER_CONSTANTS(F) \ diff --git a/src/ast.h b/src/ast.h index 1c1b95b..6b11d79 100644 --- a/src/ast.h +++ b/src/ast.h @@ -3415,13 +3415,6 @@ class AstNodeFactory FINAL BASE_EMBEDDED { VISIT_AND_RETURN(Literal, lit) } - Literal* NewStringListLiteral(ZoneList* strings, - int pos) { - Literal* lit = new (zone_) - Literal(zone_, ast_value_factory_->NewStringList(strings), pos); - VISIT_AND_RETURN(Literal, lit) - } - Literal* NewNullLiteral(int pos) { Literal* lit = new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos); diff --git a/src/messages.js b/src/messages.js index 513ffdc..a9da851 100644 --- a/src/messages.js +++ b/src/messages.js @@ -367,6 +367,23 @@ function MakeError(type, args) { return MakeGenericError($Error, type, args); } + +// The embedded versions are called from unoptimized code, with embedded +// arguments. Those arguments cannot be arrays, which are context-dependent. +function MakeTypeErrorEmbedded(type, arg) { + return MakeGenericError($TypeError, type, [arg]); +} + + +function MakeSyntaxErrorEmbedded(type, arg) { + return MakeGenericError($SyntaxError, type, [arg]); +} + + +function MakeReferenceErrorEmbedded(type, arg) { + return MakeGenericError($ReferenceError, type, [arg]); +} + /** * Find a line number given a specific source position. * @param {number} position The source position. diff --git a/src/parser.cc b/src/parser.cc index 5c85b97..ab9d6b7 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -519,7 +519,7 @@ Expression* ParserTraits::BuildUnaryExpression( Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) { return NewThrowError( parser_->ast_value_factory()->make_reference_error_string(), message, - NULL, pos); + parser_->ast_value_factory()->empty_string(), pos); } @@ -541,17 +541,11 @@ Expression* ParserTraits::NewThrowError( const AstRawString* constructor, const char* message, const AstRawString* arg, int pos) { Zone* zone = parser_->zone(); - int argc = arg != NULL ? 1 : 0; const AstRawString* type = parser_->ast_value_factory()->GetOneByteString(message); - ZoneList* array = - new (zone) ZoneList(argc, zone); - if (arg != NULL) { - array->Add(arg, zone); - } ZoneList* args = new (zone) ZoneList(2, zone); args->Add(parser_->factory()->NewStringLiteral(type, pos), zone); - args->Add(parser_->factory()->NewStringListLiteral(array, pos), zone); + args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone); CallRuntime* call_constructor = parser_->factory()->NewCallRuntime(constructor, NULL, args, pos); return parser_->factory()->NewThrow(call_constructor, pos); diff --git a/test/mjsunit/serialize-embedded-error.js b/test/mjsunit/serialize-embedded-error.js new file mode 100644 index 0000000..473c931 --- /dev/null +++ b/test/mjsunit/serialize-embedded-error.js @@ -0,0 +1,13 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// --serialize-toplevel --cache=code + +var caught = false; +try { + parseInt() = 0; +} catch(e) { + caught = true; +} +assertTrue(caught); -- 2.7.4