Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Unified Diff: runtime/vm/code_generator.cc

Issue 285543002: Recognize List constructor and turn it into CreateArray ... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/code_generator.cc
===================================================================
--- runtime/vm/code_generator.cc (revision 36136)
+++ runtime/vm/code_generator.cc (working copy)
@@ -98,8 +98,22 @@
// Arg1: array type arguments, i.e. vector of 1 type, the element type.
// Return value: newly allocated array of length arg0.
DEFINE_RUNTIME_ENTRY(AllocateArray, 2) {
- const Smi& length = Smi::CheckedHandle(arguments.ArgAt(0));
- const Array& array = Array::Handle(Array::New(length.Value()));
+ const Instance& length = Instance::CheckedHandle(arguments.ArgAt(0));
+ if (!length.IsSmi()) {
+ const String& error = String::Handle(String::NewFormatted(
+ "Length must be an integer in the range [0..%" Pd "].",
+ Array::kMaxElements));
+ Exceptions::ThrowArgumentError(error);
+ }
+ const intptr_t len = Smi::Cast(length).Value();
+ if (len < 0) {
+ const String& error = String::Handle(String::NewFormatted(
+ "Length (%" Pd ") must be an integer in the range [0..%" Pd "].",
+ len, Array::kMaxElements));
+ Exceptions::ThrowArgumentError(error);
+ }
+
+ const Array& array = Array::Handle(Array::New(len));
arguments.SetReturn(array);
TypeArguments& element_type =
TypeArguments::CheckedHandle(arguments.ArgAt(1));
« no previous file with comments | « no previous file | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698