Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
core: add ThrowError(), ThrowTypeError(), ThrowRangeError()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Mar 9, 2012
1 parent 296b7a5 commit 2589d55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
23 changes: 23 additions & 0 deletions src/node_internals.h
Expand Up @@ -22,6 +22,8 @@
#ifndef SRC_NODE_INTERNALS_H_
#define SRC_NODE_INTERNALS_H_

#include "v8.h"

namespace node {

#ifndef offset_of
Expand All @@ -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_
18 changes: 5 additions & 13 deletions src/v8_typed_array.cc
Expand Up @@ -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;
Expand Down

0 comments on commit 2589d55

Please sign in to comment.