Commit 634ffc96 authored by erikcorry's avatar erikcorry

Report syntax errors in natives when building with mksnapshot.

Review URL: http://codereview.chromium.org/10443085

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11687 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 047a7cfe
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "macro-assembler.h" #include "macro-assembler.h"
#include "objects.h" #include "objects.h"
#include "objects-visiting.h" #include "objects-visiting.h"
#include "platform.h"
#include "scopeinfo.h" #include "scopeinfo.h"
namespace v8 { namespace v8 {
...@@ -675,6 +676,43 @@ Handle<Object> Factory::NewError(const char* type, ...@@ -675,6 +676,43 @@ Handle<Object> Factory::NewError(const char* type,
} }
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, Handle<Object> Factory::NewError(const char* maker,
const char* type, const char* type,
Handle<JSArray> args) { Handle<JSArray> args) {
...@@ -683,8 +721,9 @@ Handle<Object> Factory::NewError(const char* maker, ...@@ -683,8 +721,9 @@ Handle<Object> Factory::NewError(const char* maker,
isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str)); isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str));
// If the builtins haven't been properly configured yet this error // If the builtins haven't been properly configured yet this error
// constructor may not have been defined. Bail out. // constructor may not have been defined. Bail out.
if (!fun_obj->IsJSFunction()) if (!fun_obj->IsJSFunction()) {
return undefined_value(); return EmergencyNewError(type, args);
}
Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
Handle<Object> type_obj = LookupAsciiSymbol(type); Handle<Object> type_obj = LookupAsciiSymbol(type);
Handle<Object> argv[] = { type_obj, args }; Handle<Object> argv[] = { type_obj, args };
......
...@@ -338,6 +338,7 @@ class Factory { ...@@ -338,6 +338,7 @@ class Factory {
Handle<Object> NewError(const char* maker, const char* type, Handle<Object> NewError(const char* maker, const char* type,
Handle<JSArray> args); Handle<JSArray> args);
Handle<String> EmergencyNewError(const char* type, Handle<JSArray> args);
Handle<Object> NewError(const char* maker, const char* type, Handle<Object> NewError(const char* maker, const char* type,
Vector< Handle<Object> > args); Vector< Handle<Object> > args);
Handle<Object> NewError(const char* type, Handle<Object> NewError(const char* type,
......
...@@ -1131,8 +1131,18 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) { ...@@ -1131,8 +1131,18 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
// to the console for easier debugging. // to the console for easier debugging.
int line_number = GetScriptLineNumberSafe(location->script(), int line_number = GetScriptLineNumberSafe(location->script(),
location->start_pos()); location->start_pos());
OS::PrintError("Extension or internal compilation error at line %d.\n", if (exception->IsString()) {
line_number); 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);
}
} }
} }
......
...@@ -303,7 +303,11 @@ int main(int argc, char** argv) { ...@@ -303,7 +303,11 @@ int main(int argc, char** argv) {
#endif #endif
i::Serializer::Enable(); i::Serializer::Enable();
Persistent<Context> context = v8::Context::New(); 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. // Make sure all builtin scripts are cached.
{ HandleScope scope; { HandleScope scope;
for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment