Reviewers: ulan,
Description:
Report syntax errors in natives when building with mksnapshot.
Please review this at http://codereview.chromium.org/10443085/
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M include/v8.h
M src/api.cc
M src/factory.h
M src/factory.cc
M src/isolate.cc
M src/mksnapshot.cc
M src/parser.h
Index: include/v8.h
===================================================================
--- include/v8.h (revision 11679)
+++ include/v8.h (working copy)
@@ -118,6 +118,7 @@
class Heap;
class HeapObject;
class Isolate;
+class Serializer;
}
@@ -3342,6 +3343,11 @@
~TryCatch();
/**
+ * Not for normal use.
+ */
+ TryCatch(const v8::internal::Serializer* serializer);
+
+ /**
* Returns true if an exception has been caught by this try/catch block.
*/
bool HasCaught() const;
Index: src/api.cc
===================================================================
--- src/api.cc (revision 11679)
+++ src/api.cc (working copy)
@@ -1666,6 +1666,21 @@
}
+// This doesn't actually use the serializer for anything, it's just a token
+// to get the special constructor that is only intended for mksnapshot.
+v8::TryCatch::TryCatch(const i::Serializer* serializer)
+ : isolate_(i::Isolate::Current()),
+ next_(isolate_->try_catch_handler_address()),
+ exception_(i::Smi::FromInt(0)),
+ message_(i::Smi::FromInt(0)),
+ is_verbose_(false),
+ can_continue_(true),
+ capture_message_(true),
+ rethrow_(false) {
+ isolate_->RegisterTryCatchHandler(this);
+}
+
+
v8::TryCatch::~TryCatch() {
ASSERT(isolate_ == i::Isolate::Current());
if (rethrow_) {
Index: src/factory.cc
===================================================================
--- src/factory.cc (revision 11679)
+++ src/factory.cc (working copy)
@@ -34,6 +34,7 @@
#include "macro-assembler.h"
#include "objects.h"
#include "objects-visiting.h"
+#include "platform.h"
#include "scopeinfo.h"
namespace v8 {
@@ -675,6 +676,43 @@
}
+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,
const char* type,
Handle<JSArray> args) {
@@ -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 };
Index: src/factory.h
===================================================================
--- src/factory.h (revision 11679)
+++ src/factory.h (working copy)
@@ -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,
Index: src/isolate.cc
===================================================================
--- src/isolate.cc (revision 11679)
+++ src/isolate.cc (working copy)
@@ -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);
+ }
}
}
Index: src/mksnapshot.cc
===================================================================
--- src/mksnapshot.cc (revision 11679)
+++ src/mksnapshot.cc (working copy)
@@ -302,7 +302,13 @@
}
#endif
i::Serializer::Enable();
+ TryCatch try_catch(NULL);
Persistent<Context> context = v8::Context::New();
+ if (try_catch.HasCaught()) {
+ fprintf(stderr,
+ "\nException thrown while compiling natives - see above.\n\n");
+ exit(1);
+ }
ASSERT(!context.IsEmpty());
// Make sure all builtin scripts are cached.
{ HandleScope scope;
Index: src/parser.h
===================================================================
--- src/parser.h (revision 11679)
+++ src/parser.h (working copy)
@@ -449,6 +449,9 @@
void ReportMessageAt(Scanner::Location loc,
const char* message,
Vector<Handle<String> > args);
+ void EmergencyReportMessageAt(MessageLocation* location,
+ const char* message,
+ Vector<const char*> args);
private:
// Limit on number of function parameters is chosen arbitrarily.
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev