Skip to content
This repository was archived by the owner on Feb 21, 2018. It is now read-only.

initial data_types document - #4

Closed
obastemur wants to merge 2 commits into
nodejs:masterfrom
obastemur:master
Closed

obastemur wants to merge 2 commits into
nodejs:masterfrom
obastemur:master

Conversation

@obastemur

Copy link
Copy Markdown
Contributor

A basic documentation for an initial effort to abstract the data types between JS engine(s) and addon(s).

@obastemur

Copy link
Copy Markdown
Contributor Author

Reference Issue: #2

Comment thread native/data_dypes.md Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth including a UInt32 type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK UInt32 is just a static cast from number type. Int32 and Double are the only real types backing them.

@trevnorris

Copy link
Copy Markdown
Contributor

@obastemur Thanks much for this. Doing the full review now. On the side, I'd like all the documents to word wrap. Found it introduces less noise in the git diff's over time.

Comment thread native/data_dypes.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see Symbol here.

Additionally, how would the types like Array be handled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbol wasn't in the original definition and may require additional set of native API. I left it to discussion. May I consider your comment as +1 for Symbol?

IMHO, object covers Array as it is not a separate type. API may question an object whether it is an array or not. i.e. JS_CreateArray, JS_IsArray, JS_GetArrayLength ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerning Array, the one native API users depend on is Array::Length(). Other than that, you're correct in that they're basically the same.

I mention Symbol because usage has been increasing on the JS side, and it will mostly likely be necessary for users to access object properties via a Symbol instead of a string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay adding Symbol into JSTypes.

API should covert Array::Length

GetLength -> isArray? GetArrayLength : GetStringLength
GetUtf8Length -> isArray? FAIL OR return ToString().utf8Length

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll assume that String::GetLength() would return the byte length, or the ucs2 length? Since .utf8Length() would be the equivalent of 'abc'.length

@obastemur

Copy link
Copy Markdown
Contributor Author

On the side, I'd like all the documents to word wrap. Found it introduces less noise in the git diff's over time.

Agree. Will keep in mind.

Comment thread native/data_dypes.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: backtick ObjectTemplate and FunctionTemplate. similar to anywhere that is a proper API function/method/etc.

@trevnorris

Copy link
Copy Markdown
Contributor

@obastemur Thanks much for writing this up. Have a few comments, but other than the word wrapping thing I'd be fine merging this in. I'll give it a day or two for others to ask questions, but will land it if no one chimes in.

Comment thread native/data_dypes.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop Buffer from th list? By the time this document becomes relevant, it will be implemented in terms of ArrayBuffer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes makes sense. Gonna remove Buffer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Buffer impl is technically based on Uint8Array. Mention this only because in V8, Typed Arrays don't inherit from ArrayBuffers.

May consider a more generic type. V8 has a TypedArray class that all Typed Arrays inherit from. Using something similar, it could contains information about the byte width of each index, etc.

Though ArrayBuffer will also be necessary since it must be possible to access the ArrayBuffer that backs the Typed Array.

@bnoordhuis

Copy link
Copy Markdown
Member

Left some comments. Can you wrap lines at 80 columns?

@vkurchatkin

Copy link
Copy Markdown

s/data_dypes.md/data_types.md/

@obastemur

Copy link
Copy Markdown
Contributor Author

Applied the requested changes. Thanks for all the advices.

Opaque Pointer option is also added at the end of the document. If the API is intended to be used for native addons this option might be better than a struct with void pointers inside. However, for other reasons (i.e third party is embedding node using the same API) it can be tricky. Especially when there is no detail on byte order and allocation size.

@trevnorris

Copy link
Copy Markdown
Contributor

@obastemur Awesome. Thanks for this work.

for other reasons (i.e third party is embedding node using the same API)

Forgive my dead brain. Mind elaborating this point?

I'm happy with it, and further changes can be discussed later. When I'm back close to my computer I'll merge this (with a few nit fixes I didn't want to waste your time with).

@obastemur

Copy link
Copy Markdown
Contributor Author

@trevnorris Thanks.

for other reasons (i.e third party is embedding node using the same API)

Let's say an ASP.NET solution embeds node.js as a library (CLR) and uses the same API.

Better I open this subject under another discussion item.

trevnorris pushed a commit that referenced this pull request Jul 4, 2015
PR-URL: #4
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
@trevnorris

Copy link
Copy Markdown
Contributor

Thanks much. Landed with some rewording and whitepaces fixes in b2b6309.

@trevnorris trevnorris closed this Jul 4, 2015
@bnoordhuis

Copy link
Copy Markdown
Member

It's still using void* everywhere. What are the plans for that?

@trevnorris

Copy link
Copy Markdown
Contributor

@bnoordhuis Not sure. I also noticed that ArrayBuffer wasn't added to the types list, but figured having at least something committed would bring more participation.

If you have a change feel free to throw it up.

@obastemur

Copy link
Copy Markdown
Contributor Author

Intention was to left all those parts for discussion. i.e.

Previously given data structure hides the implementation details behind a flag member and void pointers. Another idea is hiding the JSValue implementation details. (see Opaque Pointers)

I agree with @trevnorris that there will be many updates and changes to this premature first step.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants