Revision: 11687
Author: erikcorry
Date: Thu May 31 05:26:36 2012
Log: Report syntax errors in natives when building with mksnapshot.
Review URL: http://codereview.chromium.org/10443085
http://code.google.com/p/v8/source/detail?r=11687
Modified:
/branches/bleeding_edge/src/factory.cc
/branches/bleeding_edge/src/factory.h
/branches/bleeding_edge/src/isolate.cc
/branches/bleeding_edge/src/mksnapshot.cc
=======================================
--- /branches/bleeding_edge/src/factory.cc Wed May 23 07:24:29 2012
+++ /branches/bleeding_edge/src/factory.cc Thu May 31 05:26:36 2012
@@ -34,6 +34,7 @@
#include "macro-assembler.h"
#include "objects.h"
#include "objects-visiting.h"
+#include "platform.h"
#include "scopeinfo.h"
namespace v8 {
@@ -673,6 +674,43 @@
Vector< Handle<Object> > args) {
return NewError("MakeError", type, args);
}
+
+
+Handle<String> Factory::EmergencyNewError(const char* type,
+ Handle<JSArray> args) {
+ const int kBufferSize = 1000;
+ char buffer[kBufferSize];
+ size_t space = kBufferSize;
+ char* p = &buffer[0];
+
+ Vector<char> v(buffer, kBufferSize);
+ OS::StrNCpy(v, type, space);
+ space -= Min(space, strlen(type));
+ p = &buffer[kBufferSize] - space;
+
+ for (unsigned i = 0; i < ARRAY_SIZE(args); i++) {
+ if (space > 0) {
+ *p++ = ' ';
+ space--;
+ if (space > 0) {
+ MaybeObject* maybe_arg = args->GetElement(i);
+ Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg));
+ const char* arg = *arg_str->ToCString();
+ Vector<char> v2(p, space);
+ OS::StrNCpy(v2, arg, space);
+ space -= Min(space, strlen(arg));
+ p = &buffer[kBufferSize] - space;
+ }
+ }
+ }
+ if (space > 0) {
+ *p = '\0';
+ } else {
+ buffer[kBufferSize - 1] = '\0';
+ }
+ Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer),
TENURED);
+ return error_string;
+}
Handle<Object> Factory::NewError(const char* maker,
@@ -683,8 +721,9 @@
isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str));
// If the builtins haven't been properly configured yet this error
// constructor may not have been defined. Bail out.
- if (!fun_obj->IsJSFunction())
- return undefined_value();
+ if (!fun_obj->IsJSFunction()) {
+ return EmergencyNewError(type, args);
+ }
Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
Handle<Object> type_obj = LookupAsciiSymbol(type);
Handle<Object> argv[] = { type_obj, args };
=======================================
--- /branches/bleeding_edge/src/factory.h Wed May 23 07:24:29 2012
+++ /branches/bleeding_edge/src/factory.h Thu May 31 05:26:36 2012
@@ -338,6 +338,7 @@
Handle<Object> NewError(const char* maker, const char* type,
Handle<JSArray> args);
+ Handle<String> EmergencyNewError(const char* type, Handle<JSArray> args);
Handle<Object> NewError(const char* maker, const char* type,
Vector< Handle<Object> > args);
Handle<Object> NewError(const char* type,
=======================================
--- /branches/bleeding_edge/src/isolate.cc Mon Apr 23 09:42:34 2012
+++ /branches/bleeding_edge/src/isolate.cc Thu May 31 05:26:36 2012
@@ -1131,8 +1131,18 @@
// to the console for easier debugging.
int line_number = GetScriptLineNumberSafe(location->script(),
location->start_pos());
- OS::PrintError("Extension or internal compilation error at
line %d.\n",
- line_number);
+ if (exception->IsString()) {
+ OS::PrintError(
+ "Extension or internal compilation error: %s in %s at
line %d.\n",
+ *String::cast(exception)->ToCString(),
+ *String::cast(location->script()->name())->ToCString(),
+ line_number);
+ } else {
+ OS::PrintError(
+ "Extension or internal compilation error in %s at line %d.\n",
+ *String::cast(location->script()->name())->ToCString(),
+ line_number);
+ }
}
}
=======================================
--- /branches/bleeding_edge/src/mksnapshot.cc Fri Feb 3 06:16:40 2012
+++ /branches/bleeding_edge/src/mksnapshot.cc Thu May 31 05:26:36 2012
@@ -303,7 +303,11 @@
#endif
i::Serializer::Enable();
Persistent<Context> context = v8::Context::New();
- ASSERT(!context.IsEmpty());
+ if (context.IsEmpty()) {
+ fprintf(stderr,
+ "\nException thrown while compiling natives - see above.\n\n");
+ exit(1);
+ }
// Make sure all builtin scripts are cached.
{ HandleScope scope;
for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev