sfml.js 0.0.1-preview.38 → 0.0.1-preview.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +2 -4
  2. package/binding.gyp +34 -0
  3. package/lib/color.js +5 -2
  4. package/lib/image.js +17 -4
  5. package/lib/keyboard.js +3 -1
  6. package/lib/rect.js +28 -8
  7. package/lib/render_window.js +3 -1
  8. package/lib/vector2.js +26 -12
  9. package/lib/vertex.js +4 -2
  10. package/lib/video_mode.js +14 -4
  11. package/package.json +8 -3
  12. package/src/color.cc +4 -6
  13. package/src/drawable/package_plugin-inl.h +4 -3
  14. package/src/drawable/rectangle_shape.cc +3 -2
  15. package/src/drawable/shape.cc +3 -1
  16. package/src/drawable/vertex_array.cc +3 -3
  17. package/src/font.cc +6 -4
  18. package/src/image.cc +4 -5
  19. package/src/image.h +1 -1
  20. package/src/mouse.cc +2 -1
  21. package/src/plugins/transformable_plugin-inl.h +2 -2
  22. package/src/rect-inl.h +12 -8
  23. package/src/rect.h +1 -1
  24. package/src/render_window.cc +4 -3
  25. package/src/resizable_buffer.h +18 -2
  26. package/src/texture.cc +2 -2
  27. package/src/utils-inl.h +2 -2
  28. package/src/vector2-inl.h +13 -13
  29. package/src/vector2.h +3 -3
  30. package/src/vertex.cc +66 -28
  31. package/src/vertex.h +2 -2
  32. package/third_party/sfml/platform/win64/bin/openal32.dll +0 -0
  33. package/third_party/sfml/platform/win64/bin/sfml-audio-2.dll +0 -0
  34. package/third_party/sfml/platform/win64/bin/sfml-graphics-2.dll +0 -0
  35. package/third_party/sfml/platform/win64/bin/sfml-network-2.dll +0 -0
  36. package/third_party/sfml/platform/win64/bin/sfml-system-2.dll +0 -0
  37. package/third_party/sfml/platform/win64/bin/sfml-window-2.dll +0 -0
  38. package/third_party/sfml/platform/win64/lib/flac.lib +0 -0
  39. package/third_party/sfml/platform/win64/lib/freetype.lib +0 -0
  40. package/third_party/sfml/platform/win64/lib/ogg.lib +0 -0
  41. package/third_party/sfml/platform/win64/lib/openal32.lib +0 -0
  42. package/third_party/sfml/platform/win64/lib/sfml-audio.lib +0 -0
  43. package/third_party/sfml/platform/win64/lib/sfml-graphics.lib +0 -0
  44. package/third_party/sfml/platform/win64/lib/sfml-main.lib +0 -0
  45. package/third_party/sfml/platform/win64/lib/sfml-network.lib +0 -0
  46. package/third_party/sfml/platform/win64/lib/sfml-system.lib +0 -0
  47. package/third_party/sfml/platform/win64/lib/sfml-window.lib +0 -0
  48. package/third_party/sfml/platform/win64/lib/vorbis.lib +0 -0
  49. package/third_party/sfml/platform/win64/lib/vorbisenc.lib +0 -0
  50. package/third_party/sfml/platform/win64/lib/vorbisfile.lib +0 -0
  51. package/tools/keycode.js +31 -20
  52. package/tools/mouse_button.js +52 -35
  53. package/tools/symlinks.js +15 -0
package/src/rect-inl.h CHANGED
@@ -10,12 +10,11 @@ namespace rect {
10
10
  #define TEMPLATE_INNER T, NAN_T, V8_T
11
11
 
12
12
  template <typename T, typename NAN_T, class V8_T>
13
- v8::MaybeLocal<v8::Object> Rect<TEMPLATE_INNER>::NewRealInstance(
13
+ v8::MaybeLocal<v8::Value> Rect<TEMPLATE_INNER>::NewRealInstance(
14
14
  v8::Isolate* isolate, size_t argc, v8::Local<v8::Value>* argv) {
15
15
  v8::Local<v8::Function> cons = real_constructor.Get(isolate);
16
16
 
17
- v8::MaybeLocal<v8::Object> maybe_ret =
18
- cons->NewInstance(isolate->GetCurrentContext(), argc, argv);
17
+ v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, argc, argv);
19
18
  return maybe_ret;
20
19
  }
21
20
 
@@ -82,9 +81,14 @@ NAN_METHOD(Rect<TEMPLATE_INNER>::Intersects) {
82
81
  Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info[0].As<v8::Object>());
83
82
 
84
83
  v8::Local<v8::Function> cons = real_constructor.Get(info.GetIsolate());
85
- v8::Local<v8::Object> ret =
86
- cons->NewInstance(info.GetIsolate()->GetCurrentContext())
87
- .ToLocalChecked();
84
+ Nan::TryCatch try_catch;
85
+ v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, 0, nullptr);
86
+ if (maybe_ret.IsEmpty()) {
87
+ try_catch.ReThrow();
88
+ return;
89
+ }
90
+
91
+ v8::Local<v8::Object> ret = maybe_ret.ToLocalChecked().As<v8::Object>();
88
92
  Rect<T, NAN_T, V8_T>* ret_rect =
89
93
  Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(ret);
90
94
 
@@ -100,7 +104,7 @@ NAN_METHOD(Rect<TEMPLATE_INNER>::Intersects) {
100
104
  template <typename T, typename NAN_T, class V8_T> \
101
105
  NAN_METHOD(Rect<TEMPLATE_INNER>::name##Getter) { \
102
106
  Rect<T, NAN_T, V8_T>* rect = \
103
- Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.Holder()); \
107
+ Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.This()); \
104
108
  v8::Local<V8_T> ret = \
105
109
  Nan::New<V8_T>(static_cast<NAN_T>(rect->_rect.lowercase)); \
106
110
  info.GetReturnValue().Set(ret); \
@@ -115,7 +119,7 @@ NAN_METHOD(Rect<TEMPLATE_INNER>::Intersects) {
115
119
  \
116
120
  NAN_T val = maybe_value.ToLocalChecked()->Value(); \
117
121
  Rect<T, NAN_T, V8_T>* rect = \
118
- Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.Holder()); \
122
+ Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.This()); \
119
123
  rect->_rect.lowercase = static_cast<T>(val); \
120
124
  }
121
125
 
package/src/rect.h CHANGED
@@ -53,7 +53,7 @@ class Rect : public Nan::ObjectWrap {
53
53
  Nan::SetMethod(func, "setRealConstructor", SetRealConstructor);
54
54
  }
55
55
 
56
- static v8::MaybeLocal<v8::Object> NewRealInstance(
56
+ static v8::MaybeLocal<v8::Value> NewRealInstance(
57
57
  v8::Isolate* isolate,
58
58
  size_t argc = 0,
59
59
  v8::Local<v8::Value>* argv = nullptr);
@@ -16,6 +16,7 @@ using v8::Local;
16
16
  using v8::MaybeLocal;
17
17
  using v8::Object;
18
18
  using v8::String;
19
+ using v8::Value;
19
20
 
20
21
  Nan::Persistent<Function> constructor;
21
22
 
@@ -126,14 +127,14 @@ NAN_METHOD(RenderWindow::Capture) {
126
127
  sf::Image img = window->_window->capture();
127
128
 
128
129
  Nan::TryCatch try_catch;
129
- MaybeLocal<Object> maybe_img =
130
+ MaybeLocal<Value> maybe_img =
130
131
  image::Image::NewRealInstance(info.GetIsolate());
131
132
  if (maybe_img.IsEmpty()) {
132
133
  try_catch.ReThrow();
133
134
  return;
134
135
  }
135
136
 
136
- Local<Object> img_obj = maybe_img.ToLocalChecked();
137
+ Local<Object> img_obj = maybe_img.ToLocalChecked().As<Object>();
137
138
  image::Image* node_sfml_img = Nan::ObjectWrap::Unwrap<image::Image>(img_obj);
138
139
  node_sfml_img->SetInnerImage(img);
139
140
 
@@ -190,7 +191,7 @@ NAN_METHOD(RenderWindow::GetSize) {
190
191
  sf::Vector2u vec = window->_window->getSize();
191
192
 
192
193
  Nan::TryCatch try_catch;
193
- MaybeLocal<Object> maybe_vec =
194
+ MaybeLocal<Value> maybe_vec =
194
195
  vector2::Vector2U::NewRealInstance(info.GetIsolate(), vec);
195
196
  if (maybe_vec.IsEmpty()) {
196
197
  try_catch.ReThrow();
@@ -2,7 +2,11 @@
2
2
  #define SRC_RESIZABLE_BUFFER_H_
3
3
 
4
4
  #include <stdio.h>
5
+
6
+ #ifndef _WIN32
7
+ #include <string.h>
5
8
  #include <unistd.h>
9
+ #endif
6
10
 
7
11
  namespace node_sfml {
8
12
 
@@ -19,8 +23,13 @@ class ResizableBuffer {
19
23
  inline ResizableBuffer()
20
24
  : _buff(nullptr),
21
25
  _length(0),
22
- _byte_length(0),
23
- _page_size(getpagesize()) {}
26
+ _byte_length(0)
27
+ #ifndef _WIN32
28
+ ,
29
+ _page_size(getpagesize())
30
+ #endif
31
+ {
32
+ }
24
33
 
25
34
  explicit inline ResizableBuffer(size_t length) : ResizableBuffer() {
26
35
  this->Realloc(length);
@@ -44,12 +53,16 @@ class ResizableBuffer {
44
53
  _byte_length = _length * sizeof(T);
45
54
  if (!_length) return;
46
55
 
56
+ #ifndef _WIN32
47
57
  if (_byte_length >= _page_size) {
48
58
  posix_memalign(
49
59
  reinterpret_cast<void**>(&_buff), _page_size, _byte_length);
50
60
  } else {
51
61
  _buff = static_cast<T*>(valloc(_byte_length));
52
62
  }
63
+ #else
64
+ _buff = static_cast<T*>(malloc(_byte_length));
65
+ #endif
53
66
 
54
67
  memset(_buff, 0, _byte_length);
55
68
  }
@@ -80,7 +93,10 @@ class ResizableBuffer {
80
93
  T* _buff;
81
94
  size_t _length;
82
95
  size_t _byte_length;
96
+
97
+ #ifndef _WIN32
83
98
  size_t _page_size;
99
+ #endif
84
100
  };
85
101
 
86
102
  } // namespace node_sfml
package/src/texture.cc CHANGED
@@ -1,7 +1,7 @@
1
1
  #include "texture.h"
2
2
  #include "image.h"
3
3
  #include "rect.h"
4
- #include "vector2.h"
4
+ #include "vector2-inl.h"
5
5
  #include "workers/load_from_file_worker.h"
6
6
 
7
7
  namespace node_sfml {
@@ -141,7 +141,7 @@ NAN_METHOD(Texture::GetSize) {
141
141
  sf::Vector2u size = texture->_texture.getSize();
142
142
 
143
143
  Nan::TryCatch try_catch;
144
- MaybeLocal<Object> size_obj =
144
+ MaybeLocal<Value> size_obj =
145
145
  vector2::Vector2<sf::Uint32, sf::Uint32, v8::Uint32>::NewRealInstance(
146
146
  info.GetIsolate(), size);
147
147
  if (size_obj.IsEmpty()) {
package/src/utils-inl.h CHANGED
@@ -34,11 +34,11 @@ inline void V8StringToSFString(v8::Isolate* isolate,
34
34
  return;
35
35
  }
36
36
 
37
- ResizableBuffer<char> utf8_string(string_utf8_length);
37
+ ResizableBuffer<char> utf8_string(string_utf8_length + 1);
38
38
  int wrote = v8_string->WriteUtf8(isolate, *utf8_string);
39
39
 
40
40
  // TODO(XadillaX): Real length?
41
- ResizableBuffer<wchar_t> wstr(wrote << 1);
41
+ ResizableBuffer<wchar_t> wstr((wrote << 1) + 1);
42
42
  sf::Utf<8>::toWide(*utf8_string, *utf8_string + wrote, *wstr);
43
43
  sf_string = sf::String(*wstr);
44
44
  }
package/src/vector2-inl.h CHANGED
@@ -13,7 +13,7 @@ NAN_METHOD(Subtract) {
13
13
  T* right = Nan::ObjectWrap::Unwrap<T>(info[1].As<v8::Object>());
14
14
 
15
15
  Nan::TryCatch try_catch;
16
- v8::MaybeLocal<v8::Object> ret =
16
+ v8::MaybeLocal<v8::Value> ret =
17
17
  T::NewRealInstance(info.GetIsolate(), left->vector2() - right->vector2());
18
18
  if (ret.IsEmpty()) {
19
19
  try_catch.ReThrow();
@@ -29,7 +29,7 @@ NAN_METHOD(Add) {
29
29
  T* right = Nan::ObjectWrap::Unwrap<T>(info[1].As<v8::Object>());
30
30
 
31
31
  Nan::TryCatch try_catch;
32
- v8::MaybeLocal<v8::Object> ret =
32
+ v8::MaybeLocal<v8::Value> ret =
33
33
  T::NewRealInstance(info.GetIsolate(), left->vector2() + right->vector2());
34
34
  if (ret.IsEmpty()) {
35
35
  try_catch.ReThrow();
@@ -45,7 +45,7 @@ NAN_METHOD(Multiply) {
45
45
  T right = static_cast<T>(Nan::To<NAN_T>(info[1]).FromJust());
46
46
 
47
47
  Nan::TryCatch try_catch;
48
- v8::MaybeLocal<v8::Object> ret =
48
+ v8::MaybeLocal<v8::Value> ret =
49
49
  Self::NewRealInstance(info.GetIsolate(), left->vector2() * right);
50
50
  if (ret.IsEmpty()) {
51
51
  try_catch.ReThrow();
@@ -61,7 +61,7 @@ NAN_METHOD(Div) {
61
61
  T right = static_cast<T>(Nan::To<NAN_T>(info[1]).FromJust());
62
62
 
63
63
  Nan::TryCatch try_catch;
64
- v8::MaybeLocal<v8::Object> ret =
64
+ v8::MaybeLocal<v8::Value> ret =
65
65
  Self::NewRealInstance(info.GetIsolate(), left->vector2() / right);
66
66
  if (ret.IsEmpty()) {
67
67
  try_catch.ReThrow();
@@ -88,27 +88,27 @@ NAN_METHOD(NotEquals) {
88
88
  #define TEMPLATE_INNER T, NAN_T, V8_T
89
89
 
90
90
  template <typename T, typename NAN_T, class V8_T>
91
- v8::MaybeLocal<v8::Object> Vector2<TEMPLATE_INNER>::NewRealInstance(
91
+ v8::MaybeLocal<v8::Value> Vector2<TEMPLATE_INNER>::NewRealInstance(
92
92
  v8::Isolate* isolate, size_t argc, v8::Local<v8::Value>* argv) {
93
93
  v8::Local<v8::Function> cons = real_constructor.Get(isolate);
94
94
  if (cons.IsEmpty()) {
95
95
  Nan::ThrowError("`real_constructor` is not set.");
96
- return v8::MaybeLocal<v8::Object>();
96
+ return v8::MaybeLocal<v8::Value>();
97
97
  }
98
98
 
99
- v8::MaybeLocal<v8::Object> maybe_ret =
100
- cons->NewInstance(isolate->GetCurrentContext(), argc, argv);
99
+ v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, argc, argv);
100
+ cons->NewInstance(isolate->GetCurrentContext(), argc, argv);
101
101
  return maybe_ret;
102
102
  }
103
103
 
104
104
  template <typename T, typename NAN_T, class V8_T>
105
- v8::MaybeLocal<v8::Object> Vector2<TEMPLATE_INNER>::NewRealInstance(
105
+ v8::MaybeLocal<v8::Value> Vector2<TEMPLATE_INNER>::NewRealInstance(
106
106
  v8::Isolate* isolate, const sf::Vector2<T>& src) {
107
- v8::MaybeLocal<v8::Object> maybe =
107
+ v8::MaybeLocal<v8::Value> maybe =
108
108
  Vector2<TEMPLATE_INNER>::NewRealInstance(isolate);
109
109
  if (maybe.IsEmpty()) return maybe;
110
110
 
111
- v8::Local<v8::Object> vec = maybe.ToLocalChecked();
111
+ v8::Local<v8::Object> vec = maybe.ToLocalChecked().As<v8::Object>();
112
112
  Vector2<TEMPLATE_INNER>* vec_wrapper =
113
113
  Nan::ObjectWrap::Unwrap<Vector2<TEMPLATE_INNER>>(vec);
114
114
  sf::Vector2<T>& v = vec_wrapper->vector2();
@@ -150,7 +150,7 @@ NAN_METHOD(Vector2<TEMPLATE_INNER>::New) {
150
150
  template <typename T, typename NAN_T, class V8_T> \
151
151
  NAN_METHOD(Vector2<TEMPLATE_INNER>::name##Getter) { \
152
152
  Vector2<T, NAN_T, V8_T>* vec = \
153
- Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.Holder()); \
153
+ Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.This()); \
154
154
  v8::Local<V8_T> ret = \
155
155
  Nan::New<V8_T>(static_cast<NAN_T>(vec->vector2().lowercase)); \
156
156
  info.GetReturnValue().Set(ret); \
@@ -165,7 +165,7 @@ NAN_METHOD(Vector2<TEMPLATE_INNER>::New) {
165
165
  \
166
166
  NAN_T val = maybe_value.ToLocalChecked()->Value(); \
167
167
  Vector2<T, NAN_T, V8_T>* vec = \
168
- Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.Holder()); \
168
+ Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.This()); \
169
169
  vec->vector2().lowercase = static_cast<T>(val); \
170
170
  }
171
171
 
package/src/vector2.h CHANGED
@@ -74,12 +74,12 @@ class Vector2 : public Nan::ObjectWrap {
74
74
  Nan::SetMethod(func, "notEquals", NotEquals<Self>);
75
75
  }
76
76
 
77
- static v8::MaybeLocal<v8::Object> NewRealInstance(
77
+ static v8::MaybeLocal<v8::Value> NewRealInstance(
78
78
  v8::Isolate* isolate,
79
79
  size_t argc = 0,
80
80
  v8::Local<v8::Value>* argv = nullptr);
81
- static v8::MaybeLocal<v8::Object> NewRealInstance(v8::Isolate* isolate,
82
- const sf::Vector2<T>& src);
81
+ static v8::MaybeLocal<v8::Value> NewRealInstance(v8::Isolate* isolate,
82
+ const sf::Vector2<T>& src);
83
83
 
84
84
  protected:
85
85
  static NAN_METHOD(New);
package/src/vertex.cc CHANGED
@@ -5,6 +5,7 @@
5
5
  namespace node_sfml {
6
6
  namespace vertex {
7
7
 
8
+ using v8::BigInt;
8
9
  using v8::Function;
9
10
  using v8::FunctionTemplate;
10
11
  using v8::Isolate;
@@ -44,24 +45,23 @@ NAN_MODULE_INIT(Vertex::Init) {
44
45
  Nan::Set(target, name, func);
45
46
  }
46
47
 
47
- MaybeLocal<Object> Vertex::NewRealInstance(v8::Isolate* isolate,
48
- const sf::Vertex& vertex) {
48
+ MaybeLocal<Value> Vertex::NewRealInstance(v8::Isolate* isolate,
49
+ const sf::Vertex& vertex) {
49
50
  Nan::HandleScope scope;
50
51
 
51
52
  v8::Local<v8::Function> cons = real_constructor.Get(isolate);
52
53
  if (cons.IsEmpty()) {
53
54
  Nan::ThrowError("`real_constructor` is not set.");
54
- return v8::MaybeLocal<v8::Object>();
55
+ return v8::MaybeLocal<v8::Value>();
55
56
  }
56
57
 
57
- sf::Uint32 temp = reinterpret_cast<sf::Uint64>(&vertex);
58
+ sf::Uint64 temp = reinterpret_cast<sf::Uint64>(&vertex);
58
59
  Local<Value> argv[] = {
59
60
  Nan::New(vertex::Vertex::new_from_pointer_magic_number),
60
- Nan::New(temp),
61
+ BigInt::NewFromUnsigned(isolate, temp),
61
62
  };
62
63
 
63
- v8::MaybeLocal<v8::Object> maybe_ret =
64
- cons->NewInstance(isolate->GetCurrentContext(), 2, argv);
64
+ v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, 2, argv);
65
65
  return maybe_ret;
66
66
  }
67
67
 
@@ -69,7 +69,8 @@ NAN_METHOD(Vertex::New) {
69
69
  if (info[0]->IsNumber()) {
70
70
  sf::Int32 magic_number = Nan::To<sf::Int32>(info[0]).FromJust();
71
71
  if (magic_number == new_from_pointer_magic_number) {
72
- sf::Uint32 ptr = Nan::To<sf::Int32>(info[1]).FromJust();
72
+ Local<BigInt> big_int = info[1].As<BigInt>();
73
+ sf::Uint64 ptr = big_int->Uint64Value();
73
74
  sf::Vertex* vertex = reinterpret_cast<sf::Vertex*>(ptr);
74
75
  Vertex* ret = new Vertex(vertex);
75
76
  ret->Wrap(info.This());
@@ -97,7 +98,7 @@ NAN_METHOD(Vertex::SyncFromJS) {
97
98
 
98
99
  #define V(name, lowercase, snake_case, unwrap_type, inner_func) \
99
100
  NAN_METHOD(Vertex::name##Getter) { \
100
- Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.Holder()); \
101
+ Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.This()); \
101
102
  info.GetReturnValue().Set(Nan::New<Object>(vertex->_##lowercase##_wrap)); \
102
103
  vertex->_vtx->snake_case = *vertex->_##lowercase; \
103
104
  } \
@@ -106,7 +107,7 @@ NAN_METHOD(Vertex::SyncFromJS) {
106
107
  Local<Object> obj = info[0].As<Object>(); \
107
108
  unwrap_type* obj_unwrapped = Nan::ObjectWrap::Unwrap<unwrap_type>(obj); \
108
109
  \
109
- Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.Holder()); \
110
+ Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.This()); \
110
111
  vertex->_##lowercase = &obj_unwrapped->inner_func(); \
111
112
  vertex->_##lowercase##_wrap.Reset(obj); \
112
113
  vertex->SyncFromJS(k##name); \
@@ -119,21 +120,40 @@ Vertex::Vertex(sf::Vertex* src) {
119
120
  _vtx =
120
121
  std::make_unique<sf::Vertex>(src->position, src->color, src->texCoords);
121
122
 
122
- Local<Object> temp =
123
- vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->position)
124
- .ToLocalChecked();
123
+ MaybeLocal<Value> maybe_temp;
124
+ Local<Object> temp;
125
+
126
+ Nan::TryCatch try_catch;
127
+ maybe_temp =
128
+ vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->position);
129
+ if (maybe_temp.IsEmpty()) {
130
+ try_catch.ReThrow();
131
+ return;
132
+ }
133
+
134
+ temp = maybe_temp.ToLocalChecked().As<Object>();
125
135
  _position_wrap.Reset(temp);
126
136
  _position = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
127
137
 
128
- temp = color::Color::NewRealColorInstance(Isolate::GetCurrent(),
129
- _vtx->color.toInteger())
130
- .ToLocalChecked();
138
+ MaybeLocal<Object> maybe_color = color::Color::NewRealColorInstance(
139
+ Isolate::GetCurrent(), _vtx->color.toInteger());
140
+ if (maybe_color.IsEmpty()) {
141
+ try_catch.ReThrow();
142
+ return;
143
+ }
144
+
145
+ temp = maybe_color.ToLocalChecked();
131
146
  _color_wrap.Reset(temp);
132
147
  _color = &Nan::ObjectWrap::Unwrap<color::Color>(temp)->color();
133
148
 
134
- temp =
135
- vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->texCoords)
136
- .ToLocalChecked();
149
+ maybe_temp = vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(),
150
+ _vtx->texCoords);
151
+ if (maybe_temp.IsEmpty()) {
152
+ try_catch.ReThrow();
153
+ return;
154
+ }
155
+
156
+ temp = maybe_temp.ToLocalChecked().As<Object>();
137
157
  _tex_coords_wrap.Reset(temp);
138
158
  _tex_coords = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
139
159
  }
@@ -171,21 +191,39 @@ Vertex::Vertex(Local<Value> position,
171
191
  }
172
192
  }
173
193
 
174
- Local<Object> temp =
175
- vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->position)
176
- .ToLocalChecked();
194
+ Nan::TryCatch try_catch;
195
+ MaybeLocal<Value> maybe_temp;
196
+ Local<Object> temp;
197
+ maybe_temp =
198
+ vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->position);
199
+ if (maybe_temp.IsEmpty()) {
200
+ try_catch.ReThrow();
201
+ return;
202
+ }
203
+
204
+ temp = maybe_temp.ToLocalChecked().As<Object>();
177
205
  _position_wrap.Reset(temp);
178
206
  _position = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
179
207
 
180
- temp = color::Color::NewRealColorInstance(Isolate::GetCurrent(),
181
- _vtx->color.toInteger())
182
- .ToLocalChecked();
208
+ MaybeLocal<Object> maybe_color = color::Color::NewRealColorInstance(
209
+ Isolate::GetCurrent(), _vtx->color.toInteger());
210
+ if (maybe_color.IsEmpty()) {
211
+ try_catch.ReThrow();
212
+ return;
213
+ }
214
+
215
+ temp = maybe_color.ToLocalChecked().As<Object>();
183
216
  _color_wrap.Reset(temp);
184
217
  _color = &Nan::ObjectWrap::Unwrap<color::Color>(temp)->color();
185
218
 
186
- temp =
187
- vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->texCoords)
188
- .ToLocalChecked();
219
+ maybe_temp = vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(),
220
+ _vtx->texCoords);
221
+ if (maybe_temp.IsEmpty()) {
222
+ try_catch.ReThrow();
223
+ return;
224
+ }
225
+
226
+ temp = maybe_temp.ToLocalChecked().As<Object>();
189
227
  _tex_coords_wrap.Reset(temp);
190
228
  _tex_coords = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
191
229
  }
package/src/vertex.h CHANGED
@@ -25,8 +25,8 @@ class Vertex : public Nan::ObjectWrap {
25
25
  kAll,
26
26
  };
27
27
 
28
- static v8::MaybeLocal<v8::Object> NewRealInstance(v8::Isolate* isolate,
29
- const sf::Vertex& vertex);
28
+ static v8::MaybeLocal<v8::Value> NewRealInstance(v8::Isolate* isolate,
29
+ const sf::Vertex& vertex);
30
30
 
31
31
  public:
32
32
  static NAN_MODULE_INIT(Init);
package/tools/keycode.js CHANGED
@@ -4,21 +4,26 @@ const cp = require('child_process');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
 
7
- const keyboardHpp = fs.readFileSync(path.join(__dirname, '../third_party/sfml/include/SFML/Window/Keyboard.hpp'));
7
+ const keyboardHpp = fs.readFileSync(
8
+ path.join(__dirname, '../third_party/sfml/include/SFML/Window/Keyboard.hpp'));
8
9
 
9
10
  let current = 0;
10
- const extracted = /enum Key\W+{([\w\W]*)KeyCount,/.exec(keyboardHpp)[1].trim().split('\n').map(line => {
11
- line = line.trim().replace(/,\W*\/\/\/.+/, '');
12
-
13
- const arr = line.split('=').map(c => c.trim());
14
- if (arr.length >= 2) {
15
- current = parseInt(arr[1]);
16
- } else {
17
- current++;
18
- }
19
-
20
- return [ arr[0], current ];
21
- });
11
+ const extracted = /enum Key\W+{([\w\W]*)KeyCount,/
12
+ .exec(keyboardHpp)[1]
13
+ .trim()
14
+ .split('\n')
15
+ .map(line => {
16
+ line = line.trim().replace(/,\W*\/\/\/.+/, '');
17
+
18
+ const arr = line.split('=').map(c => c.trim());
19
+ if (arr.length >= 2) {
20
+ current = parseInt(arr[1]);
21
+ } else {
22
+ current++;
23
+ }
24
+
25
+ return [ arr[0], current ];
26
+ });
22
27
 
23
28
  const str = `#include <map>
24
29
  #include <string>
@@ -30,10 +35,12 @@ std::map<int, std::string> keycode_itoa;
30
35
  std::map<std::string, int> keycode_atoi;
31
36
 
32
37
  void InitKeyCode() {
33
- ${extracted.map(([ key, code ]) => {
34
- return `keycode_itoa[${code}] = "${key}";
35
- keycode_atoi["${key}"] = ${code};`;
36
- }).join('')}
38
+ ${extracted
39
+ .map(([ key, code ]) => {
40
+ return `keycode_itoa[${code}] = "${key}";
41
+ keycode_atoi["${key}"] = ${code};`;
42
+ })
43
+ .join('')}
37
44
  }
38
45
 
39
46
  } // namespace node_sfml
@@ -42,8 +49,12 @@ void InitKeyCode() {
42
49
 
43
50
  fs.writeFileSync(path.join(__dirname, '../src/gen/keycode.cc'), str);
44
51
 
45
- cp.execFileSync(
46
- path.join(__dirname, 'clang_format.js'),
47
- [ '-style=file', '-i', path.join(__dirname, '../src/gen/keycode.cc') ]);
52
+ if (process.platform !== 'win32') {
53
+ cp.execFileSync(path.join(__dirname, 'clang_format.js'), [
54
+ '-style=file',
55
+ '-i',
56
+ path.join(__dirname, '../src/gen/keycode.cc'),
57
+ ]);
58
+ }
48
59
 
49
60
  console.log('./src/gen/keyboard.cc generated.');