From 76cb9c2a39d477a64824a985ade40507e3bbade1 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Fri, 13 Feb 2026 21:34:48 -0800 Subject: feat(vanilla): add testing infrastructure and tests (NK-wjnczv) --- vanilla/node_modules/stackback/.npmignore | 1 + vanilla/node_modules/stackback/.travis.yml | 4 ++ vanilla/node_modules/stackback/README.md | 41 +++++++++++++++++++ vanilla/node_modules/stackback/formatstack.js | 57 +++++++++++++++++++++++++++ vanilla/node_modules/stackback/index.js | 46 +++++++++++++++++++++ vanilla/node_modules/stackback/package.json | 23 +++++++++++ vanilla/node_modules/stackback/test.js | 24 +++++++++++ 7 files changed, 196 insertions(+) create mode 100644 vanilla/node_modules/stackback/.npmignore create mode 100644 vanilla/node_modules/stackback/.travis.yml create mode 100644 vanilla/node_modules/stackback/README.md create mode 100644 vanilla/node_modules/stackback/formatstack.js create mode 100644 vanilla/node_modules/stackback/index.js create mode 100644 vanilla/node_modules/stackback/package.json create mode 100644 vanilla/node_modules/stackback/test.js (limited to 'vanilla/node_modules/stackback') diff --git a/vanilla/node_modules/stackback/.npmignore b/vanilla/node_modules/stackback/.npmignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/vanilla/node_modules/stackback/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/vanilla/node_modules/stackback/.travis.yml b/vanilla/node_modules/stackback/.travis.yml new file mode 100644 index 0000000..320698a --- /dev/null +++ b/vanilla/node_modules/stackback/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.6 + - 0.8 diff --git a/vanilla/node_modules/stackback/README.md b/vanilla/node_modules/stackback/README.md new file mode 100644 index 0000000..fb6bde7 --- /dev/null +++ b/vanilla/node_modules/stackback/README.md @@ -0,0 +1,41 @@ +# stackback + +Returns an array of CallSite objects for a captured stacktrace. Useful if you want to access the frame for an error object. + +## use + +```javascript +var stackback = require('stackback'); + +// error generated from somewhere +var err = new Error('some sample error'); + +// stack is an array of CallSite objects +var stack = stackback(err); +``` + +## CallSite object + +From the [V8 StackTrace API](https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi) + +The structured stack trace is an Array of CallSite objects, each of which represents a stack frame. A CallSite object defines the following methods + +getThis: returns the value of this +getTypeName: returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property. +getFunction: returns the current function +getFunctionName: returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context. +getMethodName: returns the name of the property of this or one of its prototypes that holds the current function +getFileName: if this function was defined in a script returns the name of the script +getLineNumber: if this function was defined in a script returns the current line number +getColumnNumber: if this function was defined in a script returns the current column number +getEvalOrigin: if this function was created using a call to eval returns a CallSite object representing the location where eval was called +isToplevel: is this a toplevel invocation, that is, is this the global object? +isEval: does this call take place in code defined by a call to eval? +isNative: is this call in native V8 code? +isConstructor: is this a constructor call? + +## install + +```shell +npm install stackback +``` diff --git a/vanilla/node_modules/stackback/formatstack.js b/vanilla/node_modules/stackback/formatstack.js new file mode 100644 index 0000000..d64307d --- /dev/null +++ b/vanilla/node_modules/stackback/formatstack.js @@ -0,0 +1,57 @@ +// Copyright 2012 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function FormatStackTrace(error, frames) { + var lines = []; + try { + lines.push(error.toString()); + } catch (e) { + try { + lines.push(""); + } catch (ee) { + lines.push(""); + } + } + for (var i = 0; i < frames.length; i++) { + var frame = frames[i]; + var line; + try { + line = frame.toString(); + } catch (e) { + try { + line = ""; + } catch (ee) { + // Any code that reaches this point is seriously nasty! + line = ""; + } + } + lines.push(" at " + line); + } + return lines.join("\n"); +} + +module.exports = FormatStackTrace; diff --git a/vanilla/node_modules/stackback/index.js b/vanilla/node_modules/stackback/index.js new file mode 100644 index 0000000..8b87042 --- /dev/null +++ b/vanilla/node_modules/stackback/index.js @@ -0,0 +1,46 @@ + +// v8 builtin format stack trace +// for when there was no previous prepareStackTrace function to call +var FormatStackTrace = require('./formatstack'); + +// some notes on the behavior below: +// because the 'stack' member is a one shot access variable (the raw stack is +// formatted on accessing it) +// we try to avoid modifying what the user would have wanted +// thus we use the previous value for prepareStackTrace +// +// The reason we store the callsite variable is because prepareStackTrace +// will not be called again once it has been called for a given error object +// but we want to support getting the stack out of the error multiple times (cause why not) +module.exports = function(err) { + + // save original stacktrace + var save = Error.prepareStackTrace; + + // replace capture with our function + Error.prepareStackTrace = function(err, trace) { + + // cache stack frames so we don't have to get them again + // use a non-enumerable property + Object.defineProperty(err, '_sb_callsites', { + value: trace + }); + + return (save || FormatStackTrace)(err, trace); + }; + + // force capture of the stack frames + err.stack; + + // someone already asked for the stack so we can't do this trick + // TODO fallback to string parsing? + if (!err._sb_callsites) { + return []; + } + + // return original capture function + Error.prepareStackTrace = save; + + return err._sb_callsites; +}; + diff --git a/vanilla/node_modules/stackback/package.json b/vanilla/node_modules/stackback/package.json new file mode 100644 index 0000000..3e8b7b2 --- /dev/null +++ b/vanilla/node_modules/stackback/package.json @@ -0,0 +1,23 @@ +{ + "name": "stackback", + "version": "0.0.2", + "description": "return list of CallSite objects from a captured stacktrace", + "main": "index.js", + "scripts": { + "test": "mocha --ui qunit" + }, + "repository": { + "type": "git", + "url": "git://github.com/shtylman/node-stackback.git" + }, + "keywords": [ + "stacktrace", + "trace", + "stack" + ], + "devDependencies": { + "mocha": "~1.6.0" + }, + "author": "Roman Shtylman ", + "license": "MIT" +} diff --git a/vanilla/node_modules/stackback/test.js b/vanilla/node_modules/stackback/test.js new file mode 100644 index 0000000..212b414 --- /dev/null +++ b/vanilla/node_modules/stackback/test.js @@ -0,0 +1,24 @@ +var assert = require('assert'); +var stackback = require('./'); + +test('capture', function() { + var err = new Error(); + var stack = stackback(err); + assert.equal(stack[0].getFileName(), __filename); +}); + +// calling stackback on the same error twice should work +test('multiple calls', function() { + var err = new Error(); + var stack1 = stackback(err); + var stack2 = stackback(err); + assert.equal(stack1[0].getFileName(), __filename); + assert.deepEqual(stack1, stack2); +}); + +test('string', function() { + var err = new Error(); + stackback(err); + assert.equal(typeof err.stack, 'string'); +}); + -- cgit v1.2.3