nodejs / nodejs/nan

More TypedArray helpers?

Open
#521 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3.4k
Forks
531
Avg merge
21m
Merged PRs (30d)
1

Description

Right now in node-canvas we've got stuff like this:

#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
    Local<Int32> sizeHandle = Nan::New(length);
    Local<Value> caargv[] = { sizeHandle };
    clampedArray = global->Get(Nan::New("Uint8ClampedArray").ToLocalChecked()).As<Function>()->NewInstance(1, caargv);
#else
    clampedArray = Uint8ClampedArray::New(ArrayBuffer::New(Isolate::GetCurrent(), length), 0, length);
#endif

and this:

#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION <= 10
 if (info[0]->ToObject()->GetIndexedPropertiesExternalArrayDataType() == kExternalPixelArray) {
    clampedArray = info[0]->ToObject();
    length = clampedArray->GetIndexedPropertiesExternalArrayDataLength();
#else
 if (info[0]->IsUint8ClampedArray() && info[1]->IsUint32()) {
    clampedArray = info[0].As<Uint8ClampedArray>();
    length = clampedArray->Length();
#endif

Since TypedArrayContents was added (thank you!), wondering if there's interest in adding more helpers for TypedArrays? Maybe something like:

  • Nan::New<TypedArrayT>(Nan::New<ArrayBuffer>(byteLength[, offset[, length]]))
  • Nan::New<TypedArrayT>(length)

Not so sure on argument testing. It would be nice if NAN_METHOD unified the interface so info[x]->IsUint8Array() (edit: and all the other TypedArray types) just worked. Otherwise is the only option Nan::IsUint8ClampedArray, Nan::IsUint8Array, ... and Nan::TypedArrayLength(TypedArray) ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing TypedArrayContents helper and the linked Nan pull request 486, then compare the TypedArray usage shown from src/ImageData.cc. The issue is complete only when the desired constructor, type-checking, and length-helper API are agreed and implemented with corresponding coverage; the payload does not name test files.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, node.js
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.