Permalink
Browse files

core: add ThrowError(), ThrowTypeError(), ThrowRangeError()

  • Loading branch information...
1 parent 296b7a5 commit 2589d5561191ac58f5c87efa796457c9936de73f @bnoordhuis bnoordhuis committed Mar 9, 2012
Showing with 28 additions and 13 deletions.
  1. +23 −0 src/node_internals.h
  2. +5 −13 src/v8_typed_array.cc
View
@@ -22,6 +22,8 @@
#ifndef SRC_NODE_INTERNALS_H_
#define SRC_NODE_INTERNALS_H_
+#include "v8.h"
+
namespace node {
#ifndef offset_of
@@ -40,6 +42,27 @@ namespace node {
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#endif
+// this would have been a template function were it not for the fact that g++
+// sometimes fails to resolve it...
+#define THROW_ERROR(fun) \
+ do { \
+ v8::HandleScope scope; \
+ return v8::ThrowException(fun(v8::String::New(errmsg))); \
+ } \
+ while (0)
+
+inline static v8::Handle<v8::Value> ThrowError(const char* errmsg) {
+ THROW_ERROR(v8::Exception::Error);
+}
+
+inline static v8::Handle<v8::Value> ThrowTypeError(const char* errmsg) {
+ THROW_ERROR(v8::Exception::TypeError);
+}
+
+inline static v8::Handle<v8::Value> ThrowRangeError(const char* errmsg) {
+ THROW_ERROR(v8::Exception::RangeError);
+}
+
} // namespace node
#endif // SRC_NODE_INTERNALS_H_
View
@@ -22,24 +22,16 @@
#include <stdlib.h> // calloc, etc
#include <string.h> // memmove
-#include <v8.h>
-
#include "v8_typed_array.h"
#include "node_buffer.h"
+#include "node.h"
+#include "v8.h"
namespace {
-v8::Handle<v8::Value> ThrowError(const char* msg) {
- return v8::ThrowException(v8::Exception::Error(v8::String::New(msg)));
-}
-
-v8::Handle<v8::Value> ThrowTypeError(const char* msg) {
- return v8::ThrowException(v8::Exception::TypeError(v8::String::New(msg)));
-}
-
-v8::Handle<v8::Value> ThrowRangeError(const char* msg) {
- return v8::ThrowException(v8::Exception::RangeError(v8::String::New(msg)));
-}
+using node::ThrowRangeError;
+using node::ThrowTypeError;
+using node::ThrowError;
struct BatchedMethods {
const char* name;

0 comments on commit 2589d55

Please sign in to comment.