summaryrefslogtreecommitdiff
path: root/src/node_buffer.cc
Commit message (Collapse)AuthorAgeFilesLines
* src: fix Environment::GetCurrent() usageBen Noordhuis2013-11-111-6/+13
| | | | | | Create a HandleScope before calling the Environment::GetCurrent() that takes a v8::Isolate* as an argument because it creates a handle with the call to v8::Isolate::CurrentContext().
* cpplint: disallow if one-linersFedor Indutny2013-10-171-2/+4
|
* buffer: add buf.toArrayBuffer() APITrevor Norris2013-10-111-0/+22
|
* buffer: check data is not nullTrevor Norris2013-10-111-1/+3
| | | | | | | | | | Because it's possible for the data within a Buffer instance to be altered after instantiation, or in case a user attempts to do something like the following: Buffer.prototype.fill.call({}, 10, 0, 10); It doesn't result in a segfault.
* src: add multi-context supportBen Noordhuis2013-09-061-17/+50
| | | | | | | | | | | | | | | | | | | | | | | This commit makes it possible to use multiple V8 execution contexts within a single event loop. Put another way, handle and request wrap objects now "remember" the context they belong to and switch back to that context when the time comes to call into JS land. This could have been done in a quick and hacky way by calling v8::Object::GetCreationContext() on the wrap object right before making a callback but that leaves a fairly wide margin for bugs. Instead, we make the context explicit through a new Environment class that encapsulates everything (or almost everything) that belongs to the context. Variables that used to be a static or a global are now members of the aforementioned class. An additional benefit is that this approach should make it relatively straightforward to add full isolate support in due course. There is no JavaScript API yet but that will be added in the near future. This work was graciously sponsored by GitHub, Inc.
* src: fix up unused/unordered importsBen Noordhuis2013-08-271-1/+0
|
* buffer: add NativeBuffer APITrevor Norris2013-08-261-26/+8
| | | | | | | | Due to a lot of the util.is* checks there was much unnecessary overhead for the most common use case of Buffer. Which is creating a new Buffer instance for data from incoming I/O. NativeBuffer is a simple way to bypass all the unneeded checks and simply hand back a Buffer instance while setting the length.
* buffer: lintTrevor Norris2013-08-191-1/+0
| | | | | This and b80d11d are my fault. An unrelated test was failing, which prevents {js,cpp}lint from running automatically.
* buffer: don't call ByteLength for simple encodingsTrevor Norris2013-08-161-3/+8
| | | | | For several encodings the byte length is simple arithmetic. Don't call into C++ in those cases.
* src: use v8::String::NewFrom*() functionsBen Noordhuis2013-08-091-4/+7
| | | | | | | | | | | | | | | | | | | | | | * Change calls to String::New() and String::NewSymbol() to their respective one-byte, two-byte and UTF-8 counterparts. * Add a FIXED_ONE_BYTE_STRING macro that takes a string literal and turns it into a v8::Local<v8::String>. * Add helper functions that make v8::String::NewFromOneByte() easier to work with. Said function expects a `const uint8_t*` but almost every call site deals with `const char*` or `const unsigned char*`. Helps us avoid doing reinterpret_casts all over the place. * Code that handles file system paths keeps using UTF-8 for backwards compatibility reasons. At least now the use of UTF-8 is explicit. * Remove v8::String::NewSymbol() entirely. Almost all call sites were effectively minor de-optimizations. If you create a string only once, there is no point in making it a symbol. If you are create the same string repeatedly, it should probably be cached in a persistent handle.
* src: lint c++ codeFedor Indutny2013-07-311-2/+0
|
* buffer: return offset for end of last writeTrevor Norris2013-07-191-8/+14
|
* build: fix windows buildBen Noordhuis2013-07-111-1/+0
| | | | | | | Be very careful with forward declarations, MSVC is quite picky and rather stupid about it. Fixes #5810.
* lib, src: upgrade after v8 api changeBen Noordhuis2013-07-061-84/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a big commit that touches just about every file in the src/ directory. The V8 API has changed in significant ways. The most important changes are: * Binding functions take a const v8::FunctionCallbackInfo<T>& argument rather than a const v8::Arguments& argument. * Binding functions return void rather than v8::Handle<v8::Value>. The return value is returned with the args.GetReturnValue().Set() family of functions. * v8::Persistent<T> no longer derives from v8::Handle<T> and no longer allows you to directly dereference the object that the persistent handle points to. This means that the common pattern of caching oft-used JS values in a persistent handle no longer quite works, you first need to reconstruct a v8::Local<T> from the persistent handle with the Local<T>::New(isolate, persistent) factory method. A handful of (internal) convenience classes and functions have been added to make dealing with the new API a little easier. The most visible one is node::Cached<T>, which wraps a v8::Persistent<T> with some template sugar. It can hold arbitrary types but so far it's exclusively used for v8::Strings (which was by far the most commonly cached handle type.)
* buffer: use macroFedor Indutny2013-07-061-48/+26
|
* smalloc: use malloc instead of newTrevor Norris2013-07-031-3/+24
| | | | To use realloc the implementation had to be changed to use malloc/free.
* buffer: fix gcc 4.2 build breakageBen Noordhuis2013-06-201-1/+3
| | | | | | | | | | | | | | | | gcc 4.2 on OS X gets confused about the call to node::Buffer::Data(). Fully qualify the function name to help it along. Fixes the following build error: ../../deps/v8/include/v8.h: In function ‘char* node::Buffer::Data(v8::Handle<v8::Value>)’: ../../deps/v8/include/v8.h:900: error: ‘class v8::Data’ is not a function, ../../src/node_buffer.h:38: error: conflict with ‘char* node::Buffer::Data(v8::Handle<v8::Object>)’ ../../src/node_buffer.cc:94: error: in call to ‘Data’
* buffer: write strings directly from callTrevor Norris2013-06-191-6/+7
| | | | | | | | Buffer(<String>) used to pass the string to js where it would then be passed back to cpp for processing. Now only the buffer object instantiation is done in js and the string is processed in cpp. Also added a Buffer api that also accepts the encoding.
* buffer: implement new fill behaviorTrevor Norris2013-06-181-8/+32
| | | | | | | | | Old fill would take the char code of the first character and wrap around the int to fit in the 127 range. Now fill will duplicate whatever string is given through the entirety of the buffer. Note: There is one bug around ending on a partial fill of any character outside the ASCII range.
* buffer: remove c-style castsTrevor Norris2013-06-181-5/+3
|
* buffer: use smalloc as backing data storeTrevor Norris2013-06-181-406/+317
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Memory allocations are now done through smalloc. The Buffer cc class has been removed completely, but for backwards compatibility have left the namespace as Buffer. The .parent attribute is only set if the Buffer is a slice of an allocation. Which is then set to the alloc object (not a Buffer). The .offset attribute is now a ReadOnly set to 0, for backwards compatibility. I'd like to remove it in the future (pre v1.0). A few alterations have been made to how arguments are either coerced or thrown. All primitives will now be coerced to their respective values, and (most) all out of range index requests will throw. The indexes that are coerced were left for backwards compatibility. For example: Buffer slice operates more like Array slice, and coerces instead of throwing out of range indexes. This may change in the future. The reason for wanting to throw for out of range indexes is because giving js access to raw memory has high potential risk. To mitigate that it's easier to make sure the developer is always quickly alerted to the fact that their code is attempting to access beyond memory bounds. Because SlowBuffer will be deprecated, and simply returns a new Buffer instance, all tests on SlowBuffer have been removed. Heapdumps will now show usage under "smalloc" instead of "Buffer". ParseArrayIndex was added to node_internals to support proper uint argument checking/coercion for external array data indexes. SlabAllocator had to be updated since handle_ no longer exists.
* buffer: guard against integer overflowBen Noordhuis2013-05-301-1/+1
|
* buffer: simplify ReadFloatGeneric offset checksBen Noordhuis2013-05-301-3/+2
|
* buffer: guard against pointer aliasing issuesBen Noordhuis2013-05-301-35/+36
|
* Merge remote-tracking branch 'ry/v0.10'isaacs2013-05-271-1/+7
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: AUTHORS ChangeLog configure deps/uv/ChangeLog deps/uv/src/unix/darwin.c deps/uv/src/unix/stream.c deps/uv/src/version.c deps/v8/src/isolate.cc deps/v8/src/version.cc lib/http.js src/node_version.h
| * buffer: special case empty string writesTimothy J Fontaine2013-05-231-1/+9
| | | | | | | | | | Prior to 119354f we specifically handled passing a zero length string to write on a buffer, restore that functionality.
* | Merge remote-tracking branch 'ry/v0.10' into masterisaacs2013-05-171-525/+56
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: AUTHORS ChangeLog deps/uv/ChangeLog deps/uv/config-unix.mk deps/uv/src/unix/stream.c deps/uv/src/version.c deps/uv/uv.gyp src/node.cc src/node_buffer.cc src/node_crypto.cc src/node_version.h src/stream_wrap.cc src/stream_wrap.h
| * buffer: DRY string encoding using StringBytesisaacs2013-05-141-550/+63
| | | | | | | | | | | | | | This also templatizes the Buffer::*Slice functions, and the template function probably cannot be safely used outside of Node. However, it also SHOULD not be used outside of Node, so this is arguably a feature as well as a caveat.
* | buffer: upgrade to new V8 profiler APIBen Noordhuis2013-04-171-1/+2
| |
* | lint: add isolate, remove semicolonTrevor Norris2013-03-301-1/+1
| |
* | buffer: remove _charsWrittenTrevor Norris2013-03-261-26/+0
| | | | | | | | | | | | | | _charsWritten is an internal property that was constantly written to, but never read from. So it has been removed. Removed documentation reference as well.
* | src: write ascii strings using WriteOneByteTrevor Norris2013-03-211-5/+5
| | | | | | | | | | WriteAscii will be deprecated soon from v8, and performance has regressed. The v8 team recommended using WriteOneByte instead.
* | src: pass Isolate to all applicable apiTrevor Norris2013-03-201-53/+55
| | | | | | | | | | | | Update the api to pass node_isolate to all supported methods. Much thanks to Ben Noordhuis and his work in 51f6e6a.
* | bindings: update apiTrevor Norris2013-03-201-5/+7
|/ | | | | | | | | | | | | | | | | | | | | All compile time warnings about using deprecated APIs have been suppressed by updating node's API. Though there are still many function calls that can accept Isolate, and still need to be updated. node_isolate had to be added as an extern variable in node.h and node_object_wrap.h Also a couple small fixes for Error handling. Before v8 3.16.6 the error stack message was lazily written when it was needed, which allowed you to change the message after instantiation. Then the stack would be written with the new message the first time it was accessed. Though that has changed. Now it creates the stack message on instantiation. So setting a different message afterwards won't be displayed. This is not a complete fix for the problem. Getting error without any message isn't very useful.
* buffer: speed up ascii character scanningBen Noordhuis2013-03-081-2/+90
| | | | | Speed up ASCII character scanning and conversion by 25% to 30% by scanning and converting whole words instead of individual bytes.
* buffer: strip high bits when converting to asciiBen Noordhuis2013-03-081-2/+26
| | | | | | | | | | | | | | Consider the following example: console.log(Buffer('ú').toString('ascii')); Before this commit, the contents of the buffer was used as-is and hence it prints 'ú'. Now, it prints 'C:'. Perhaps not much of an improvement but it conforms to what the documentation says it does: strip off the high bits. Fixes #4371.
* src, test: downgrade to v8 3.14 apiBen Noordhuis2013-02-251-30/+28
|
* buffer: fix Buffer::HasInstance() checkBen Noordhuis2013-02-101-3/+15
| | | | | It was returning true for typed arrays. Check that the object was instantiated with the Buffer constructor.
* Merge remote-tracking branch 'ry/v0.8' into masterisaacs2013-02-061-4/+4
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: AUTHORS ChangeLog deps/npm/html/api/bin.html deps/npm/html/api/bugs.html deps/npm/html/api/commands.html deps/npm/html/api/config.html deps/npm/html/api/deprecate.html deps/npm/html/api/docs.html deps/npm/html/api/edit.html deps/npm/html/api/explore.html deps/npm/html/api/help-search.html deps/npm/html/api/init.html deps/npm/html/api/install.html deps/npm/html/api/link.html deps/npm/html/api/load.html deps/npm/html/api/ls.html deps/npm/html/api/npm.html deps/npm/html/api/outdated.html deps/npm/html/api/owner.html deps/npm/html/api/pack.html deps/npm/html/api/prefix.html deps/npm/html/api/prune.html deps/npm/html/api/publish.html deps/npm/html/api/rebuild.html deps/npm/html/api/restart.html deps/npm/html/api/root.html deps/npm/html/api/run-script.html deps/npm/html/api/search.html deps/npm/html/api/shrinkwrap.html deps/npm/html/api/start.html deps/npm/html/api/stop.html deps/npm/html/api/submodule.html deps/npm/html/api/tag.html deps/npm/html/api/test.html deps/npm/html/api/uninstall.html deps/npm/html/api/unpublish.html deps/npm/html/api/update.html deps/npm/html/api/version.html deps/npm/html/api/view.html deps/npm/html/api/whoami.html deps/npm/html/doc/README.html deps/npm/html/doc/adduser.html deps/npm/html/doc/bin.html deps/npm/html/doc/bugs.html deps/npm/html/doc/build.html deps/npm/html/doc/bundle.html deps/npm/html/doc/cache.html deps/npm/html/doc/changelog.html deps/npm/html/doc/coding-style.html deps/npm/html/doc/completion.html deps/npm/html/doc/config.html deps/npm/html/doc/dedupe.html deps/npm/html/doc/deprecate.html deps/npm/html/doc/developers.html deps/npm/html/doc/disputes.html deps/npm/html/doc/docs.html deps/npm/html/doc/edit.html deps/npm/html/doc/explore.html deps/npm/html/doc/faq.html deps/npm/html/doc/folders.html deps/npm/html/doc/global.html deps/npm/html/doc/help-search.html deps/npm/html/doc/help.html deps/npm/html/doc/index.html deps/npm/html/doc/init.html deps/npm/html/doc/install.html deps/npm/html/doc/json.html deps/npm/html/doc/link.html deps/npm/html/doc/ls.html deps/npm/html/doc/npm.html deps/npm/html/doc/outdated.html deps/npm/html/doc/owner.html deps/npm/html/doc/pack.html deps/npm/html/doc/prefix.html deps/npm/html/doc/prune.html deps/npm/html/doc/publish.html deps/npm/html/doc/rebuild.html deps/npm/html/doc/registry.html deps/npm/html/doc/removing-npm.html deps/npm/html/doc/restart.html deps/npm/html/doc/rm.html deps/npm/html/doc/root.html deps/npm/html/doc/run-script.html deps/npm/html/doc/scripts.html deps/npm/html/doc/search.html deps/npm/html/doc/semver.html deps/npm/html/doc/shrinkwrap.html deps/npm/html/doc/star.html deps/npm/html/doc/start.html deps/npm/html/doc/stop.html deps/npm/html/doc/submodule.html deps/npm/html/doc/tag.html deps/npm/html/doc/test.html deps/npm/html/doc/uninstall.html deps/npm/html/doc/unpublish.html deps/npm/html/doc/update.html deps/npm/html/doc/version.html deps/npm/html/doc/view.html deps/npm/html/doc/whoami.html deps/npm/man/man1/global.1 deps/npm/man/man1/ls.1 deps/npm/man/man1/npm.1 deps/npm/man/man1/rm.1 deps/npm/man/man3/npm.3 deps/npm/node_modules/glob/glob.js deps/npm/node_modules/glob/package.json deps/npm/node_modules/node-gyp/package.json deps/npm/node_modules/npm-registry-client/package.json deps/npm/node_modules/npmconf/package.json deps/npm/node_modules/read-installed/package.json deps/npm/node_modules/rimraf/package.json deps/npm/node_modules/rimraf/rimraf.js deps/npm/package.json deps/uv/src/win/error.c doc/api/crypto.markdown lib/zlib.js src/node_version.h src/node_zlib.cc test/simple/test-buffer.js
| * buffer: slow buffer copy compatibility fixTrevor Norris2013-01-251-4/+4
| | | | | | | | | | | | | | | | | | | | Fix issue where SlowBuffers couldn't be passed as target to Buffer copy(). Also included checks to see if Argument parameters are defined before assigning their values. This offered ~3x's performance gain. Backport of 16bbecc from master branch. Closes #4633.
* | buffer: optimize Buffer.prototype.write(s, 'hex')Ben Noordhuis2013-02-021-0/+67
| | | | | | | | | | | | | | | | | | | | | | | | Move the implementation to C++ land. This is similar to commit 3f65916 but this time for the write() function and the Buffer(s, 'hex') constructor. Speeds up the benchmark below about 24x (2.6s vs 1:02m). var s = 'f'; for (var i = 0; i < 26; ++i) s += s; // 64 MB Buffer(s, 'hex');
* | buffer: optimize Buffer.prototype.toString('hex')Ben Noordhuis2013-02-011-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | Move the implementation to C++ land. The old JS implementation used string concatenation, was dog slow and consumed copious amounts of memory for large buffers. Example: var buf = Buffer(0x1000000); // 16 MB buf.toString('hex') // Used 3+ GB of memory. The new implementation operates in O(n) time and space. Fixes #4700.
* | buffer: fix Buffer::Copy regression from 00b4b7bBen Noordhuis2013-01-271-1/+2
| | | | | | | | | | | | | | | | | | | | If the end argument is omitted or not a number, make it default to the end of the buffer, not zero. Ideally, it should not matter what it defaults to because the JS shim in lib/buffer.js should handle that but there are still several places in node.js core that secrete SlowBuffers, hence Buffer::Copy() gets called without going through Buffer.prototype.copy() first.
* | buffer: remove minor Buffer::Copy deoptimizationsBen Noordhuis2013-01-251-5/+4
| | | | | | | | | | | | | | | | * Omit ToObject() call. Buffer::Data() and Buffer::Length() know how to deal with Values. * Don't check if the argument is undefined because it realistically never is and undefined->integer coercion achieves the same thing.
* | buffer: error and misc cleanupTrevor Norris2013-01-251-33/+18
| | | | | | | | | | | | Changed types of errors thrown to be more indicative of what the error represents. Also removed a few unnecessary uses of the v8 fully quantified typename.
* | buffer: slow buffer copy compatibility fixTrevor Norris2013-01-251-4/+4
| | | | | | | | | | | | | | | | Fix issue where SlowBuffers couldn't be passed as target to Buffer copy(). Also included checks to see if Argument parameters are defined before assigning their values. This offered ~3x's performance gain.
* | buffer: remove float write range checksTrevor Norris2013-01-231-45/+5
| | | | | | | | | | | | Removed range checks when writing float values, and removed a few includes and defines. Also updated api docs to reflect that invalid 32 bit float is an unspecified behavior.
* | Merge remote-tracking branch 'ry/v0.8' into masterisaacs2013-01-181-0/+13
|\ \ | |/ | | | | | | | | | | | | Conflicts: AUTHORS ChangeLog src/node_version.h test/simple/test-buffer.js
| * buffer: reject negative SlowBuffer offsetsBen Noordhuis2013-01-171-0/+13
| | | | | | | | | | | | | | Reject negative offsets in SlowBuffer::MakeFastBuffer(), it allows the creation of buffers that point to arbitrary addresses. Reported by Trevor Norris.
* | buffer: Define INFINITY for MSVC compilerisaacs2013-01-181-0/+24
| |