Browse Source

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

v0.9.1-release
Ben Noordhuis 13 years ago
parent
commit
2589d55611
  1. 23
      src/node_internals.h
  2. 18
      src/v8_typed_array.cc

23
src/node_internals.h

@ -22,6 +22,8 @@
#ifndef SRC_NODE_INTERNALS_H_ #ifndef SRC_NODE_INTERNALS_H_
#define SRC_NODE_INTERNALS_H_ #define SRC_NODE_INTERNALS_H_
#include "v8.h"
namespace node { namespace node {
#ifndef offset_of #ifndef offset_of
@ -40,6 +42,27 @@ namespace node {
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#endif #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 } // namespace node
#endif // SRC_NODE_INTERNALS_H_ #endif // SRC_NODE_INTERNALS_H_

18
src/v8_typed_array.cc

@ -22,24 +22,16 @@
#include <stdlib.h> // calloc, etc #include <stdlib.h> // calloc, etc
#include <string.h> // memmove #include <string.h> // memmove
#include <v8.h>
#include "v8_typed_array.h" #include "v8_typed_array.h"
#include "node_buffer.h" #include "node_buffer.h"
#include "node.h"
#include "v8.h"
namespace { namespace {
v8::Handle<v8::Value> ThrowError(const char* msg) { using node::ThrowRangeError;
return v8::ThrowException(v8::Exception::Error(v8::String::New(msg))); using node::ThrowTypeError;
} using node::ThrowError;
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)));
}
struct BatchedMethods { struct BatchedMethods {
const char* name; const char* name;

Loading…
Cancel
Save