| 124 | |
| 125 | |
| 126 | inline v8::Local<v8::Object> makeTypedArray(ArrayType type, uint32_t length) { |
| 127 | |
| 128 | const char *name = ArrayTypeToString(type); |
| 129 | if (!name) { |
| 130 | Nan::ThrowError("Unsupported array type"); |
| 131 | return Nan::New<v8::Object>(); |
| 132 | } |
| 133 | |
| 134 | auto typedArrayConstructor = Nan::Get(Nan::GetCurrentContext()->Global(),Nan::New(name).ToLocalChecked()).ToLocalChecked(); |
| 135 | |
| 136 | if (typedArrayConstructor.IsEmpty() || !typedArrayConstructor->IsFunction()) { |
| 137 | Nan::ThrowError("Error getting typed array constructor"); |
| 138 | return Nan::New<v8::Object>(); |
| 139 | } |
| 140 | |
| 141 | v8::Local<v8::Function> constructor = Nan::To<v8::Function>(typedArrayConstructor).ToLocalChecked(); |
| 142 | |
| 143 | const int argc = 1; |
| 144 | v8::Local<v8::Value> argv[1] = { Nan::New(length) }; |
| 145 | v8::Local<v8::Object> array = constructor->NewInstance(Nan::GetCurrentContext(),argc, argv).ToLocalChecked(); |
| 146 | |
| 147 | if (array.IsEmpty() || !array->IsObject()) { |
| 148 | Nan::ThrowError("Error creating TypedArray"); |
| 149 | return v8::Local<v8::Object>(); |
| 150 | } |
| 151 | return array; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | inline v8::Local<v8::Object> makeFloat32Array(const float* data, uint32_t length) { |
no test coverage detected