@ohos-ports/nbind 0.0.0-stage → 0.3.15-beta.1

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 (92) hide show
  1. package/.editorconfig +7 -0
  2. package/LICENSE +22 -0
  3. package/README.md +1393 -2
  4. package/autogypi.json +11 -0
  5. package/bin/ci-trigger +40 -0
  6. package/bin/copyasm.js +77 -0
  7. package/bin/emcc +21 -0
  8. package/bin/emcc-path.js +7 -0
  9. package/bin/ndts.js +22 -0
  10. package/config.js +7 -0
  11. package/dist/Type.d.ts +92 -0
  12. package/dist/Type.js +180 -0
  13. package/dist/common.d.ts +9 -0
  14. package/dist/common.js +10 -0
  15. package/dist/em-api.js +2353 -0
  16. package/dist/int64.d.ts +9 -0
  17. package/dist/int64.js +64 -0
  18. package/dist/nbind.d.ts +49 -0
  19. package/dist/nbind.js +154 -0
  20. package/dist/reflect.d.ts +69 -0
  21. package/dist/reflect.js +261 -0
  22. package/dist/shim.d.ts +1 -0
  23. package/dist/shim.js +2 -0
  24. package/dist/todts.d.ts +5 -0
  25. package/dist/todts.js +146 -0
  26. package/include/nbind/ArgStorage.h +67 -0
  27. package/include/nbind/BindClass.h +290 -0
  28. package/include/nbind/BindDefiner.h +295 -0
  29. package/include/nbind/Buffer.h +50 -0
  30. package/include/nbind/FunctionDefiner.h +51 -0
  31. package/include/nbind/MethodDef.h +50 -0
  32. package/include/nbind/Policy.h +255 -0
  33. package/include/nbind/TypeID.h +84 -0
  34. package/include/nbind/TypeStd.h +66 -0
  35. package/include/nbind/TypeTransformer.h +38 -0
  36. package/include/nbind/api.h +100 -0
  37. package/include/nbind/common.h +22 -0
  38. package/include/nbind/em/ArgFromWire.h +31 -0
  39. package/include/nbind/em/BindingStd.h +221 -0
  40. package/include/nbind/em/BindingType.h +204 -0
  41. package/include/nbind/em/Buffer.h +37 -0
  42. package/include/nbind/em/Callback.h +186 -0
  43. package/include/nbind/em/Caller.h +61 -0
  44. package/include/nbind/em/Creator.h +30 -0
  45. package/include/nbind/em/External.h +63 -0
  46. package/include/nbind/em/Int64.h +131 -0
  47. package/include/nbind/em/NBind.h +63 -0
  48. package/include/nbind/em/Pool.h +34 -0
  49. package/include/nbind/em/StdFunction.h +40 -0
  50. package/include/nbind/em/ValueObj.h +54 -0
  51. package/include/nbind/nbind.h +19 -0
  52. package/include/nbind/noconflict.h +91 -0
  53. package/include/nbind/signature/BaseSignature.h +238 -0
  54. package/include/nbind/signature/CallbackSignature.h +59 -0
  55. package/include/nbind/signature/ConstructorSignature.h +76 -0
  56. package/include/nbind/signature/FunctionSignature.h +63 -0
  57. package/include/nbind/signature/GetterSignature.h +62 -0
  58. package/include/nbind/signature/MethodSignature.h +61 -0
  59. package/include/nbind/signature/SetterSignature.h +63 -0
  60. package/include/nbind/signature/SignatureParam.h +39 -0
  61. package/include/nbind/v8/ArgFromWire.h +69 -0
  62. package/include/nbind/v8/BindWrapper.h +295 -0
  63. package/include/nbind/v8/BindingStd.h +180 -0
  64. package/include/nbind/v8/BindingType.h +241 -0
  65. package/include/nbind/v8/Buffer.h +59 -0
  66. package/include/nbind/v8/Callback.h +165 -0
  67. package/include/nbind/v8/Caller.h +140 -0
  68. package/include/nbind/v8/Convert.h +80 -0
  69. package/include/nbind/v8/Creator.h +26 -0
  70. package/include/nbind/v8/External.h +119 -0
  71. package/include/nbind/v8/Int64.h +195 -0
  72. package/include/nbind/v8/NBind.h +63 -0
  73. package/include/nbind/v8/Output.h +36 -0
  74. package/include/nbind/v8/Overloader.h +215 -0
  75. package/include/nbind/v8/StdFunction.h +44 -0
  76. package/include/nbind/v8/ValueObj.h +137 -0
  77. package/include/nbind/wire.h +79 -0
  78. package/package.json +69 -4
  79. package/src/checkver.js +31 -0
  80. package/src/common.cc +129 -0
  81. package/src/em/Binding.cc +313 -0
  82. package/src/em/tsconfig.json +22 -0
  83. package/src/nbind-common.gypi +14 -0
  84. package/src/nbind.gypi +98 -0
  85. package/src/post.js +2 -0
  86. package/src/pre.js +48 -0
  87. package/src/reflect.cc +170 -0
  88. package/src/symbols.txt +1 -0
  89. package/src/tsconfig.json +23 -0
  90. package/src/tslint.json +86 -0
  91. package/src/v8/Binding.cc +391 -0
  92. package/src/v8/Buffer.cc +73 -0
@@ -0,0 +1,73 @@
1
+ // This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
2
+ // Released under the MIT license, see LICENSE.
3
+
4
+ #ifdef BUILDING_NODE_EXTENSION
5
+
6
+ #include "nbind/nbind.h"
7
+
8
+ using namespace nbind;
9
+
10
+ #if NODE_MODULE_VERSION >= 14 // >= Node.js 0.12
11
+
12
+ void BindingType<Buffer> :: initFromArray(WireType arg, Buffer &result) {
13
+ v8::Local<v8::ArrayBuffer> buf;
14
+ unsigned char *data = nullptr;
15
+ size_t offset = 0;
16
+ size_t length;
17
+
18
+ if(arg->IsArrayBufferView()) {
19
+ v8::Local<v8::ArrayBufferView> view = arg.template As<v8::ArrayBufferView>();
20
+
21
+ buf = view->Buffer();
22
+ offset = view->ByteOffset();
23
+ length = view->ByteLength();
24
+ } else {
25
+ buf = arg.template As<v8::ArrayBuffer>();
26
+ length = buf->ByteLength();
27
+ }
28
+
29
+ # if NODE_MODULE_VERSION >= 45 // >= IO.js 3.0
30
+ data = static_cast<unsigned char *>(buf->Data());
31
+ # else // < IO.js 3.0
32
+ if(buf->IsExternal()) {
33
+ // If the buffer is already externalized,
34
+ // get the pointer if we have it.
35
+ auto ptr = Nan::Get(
36
+ Nan::To<v8::Object>(buf).ToLocalChecked(),
37
+ Nan::New<v8::String>("__nbindData").ToLocalChecked()
38
+ ).ToLocalChecked();
39
+
40
+ if(!ptr->IsExternal()) {
41
+ // Cannot get the data pointer because someone else
42
+ // externalized the buffer. Signal error by returning
43
+ // data of zero length at nullptr.
44
+ offset = 0;
45
+ length = 0;
46
+ } else {
47
+ data = static_cast<unsigned char *>(
48
+ v8::Local<v8::External>::Cast(ptr)->Value()
49
+ );
50
+ }
51
+ } else {
52
+ data = static_cast<unsigned char *>(buf->Externalize().Data());
53
+
54
+ // Set callback to free the data.
55
+ result.handle.addDestructor(&Buffer :: destroy, data);
56
+
57
+ // Buffer can only be externalized once,
58
+ // so store our precious pointer with it.
59
+ Nan::Set(
60
+ Nan::To<v8::Object>(buf).ToLocalChecked(),
61
+ Nan::New<v8::String>("__nbindData").ToLocalChecked(),
62
+ Nan::New<v8::External>(data)
63
+ );
64
+ }
65
+ # endif // < IO.js 3.0
66
+
67
+ result.ptr = data + offset;
68
+ result.len = length;
69
+ }
70
+
71
+ #endif // >= Node.js 0.12
72
+
73
+ #endif