Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

function-tree

Package Overview
Dependencies
Maintainers
1
Versions
487
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

function-tree - npm Package Compare versions

Comparing version 0.3.9 to 0.3.10

2

package.json
{
"name": "function-tree",
"version": "0.3.9",
"version": "0.3.10",
"description": "When a function is not enough",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -5,2 +5,6 @@ module.exports = function (extendedContext) {

if (context.debugger) {
// Grab the prototype to insert methods defined there into instance later.
// We only grab actual added prototypes on first level, not nested and not
// where prototype is base prototypes like Objects and Functions
var proto = null

@@ -15,21 +19,23 @@ if (

var existingContextfunction = extendedContext[key]
// The value might be a function that is already wrapped, try grabbing the original
var existingContextValue = extendedContext[key].__ft_originFunc || extendedContext[key]
context[key] = (
typeof extendedContext[key] === 'function' ?
function () {
context.debugger.send({
method: key,
color: context.debugger.getColor(key),
args: [].slice.call(arguments)
})
extendedContext[key].apply(context, arguments)
}
:
Object.create(extendedContext[key])
)
context[key] = Object.keys(extendedContext[key]).reduce(function (obj, objKey) {
if (typeof extendedContext[key][objKey] === 'function') {
var originalFunc = extendedContext[key][objKey]
// If the context value is a function, wrap it
if (typeof existingContextValue === 'function') {
context[key] = function () {
context.debugger.send({
method: key,
color: context.debugger.getColor(key),
args: [].slice.call(arguments)
})
existingContextValue.apply(context, arguments)
};
context[key].__ft_originFunc = existingContextValue
}
// Go through keys original value and wrap any attached methods
context[key] = Object.keys(existingContextValue).reduce(function (obj, objKey) {
if (typeof existingContextValue[objKey] === 'function') {
var originalFunc = existingContextValue[objKey].__ft_originFunc || existingContextValue[objKey]
obj[objKey] = function () {

@@ -41,13 +47,15 @@ context.debugger.send({

})
return originalFunc.apply(extendedContext[key], arguments)
return originalFunc.apply(obj, arguments)
}
existingContextValue[objKey].__ft_originFunc = originalFunc
}
return obj
}, context[key])
}, context[key] || existingContextValue) // Depending it being a function that has been wrapped or the original object
// Grab methods of prototype and add it
if (proto) {
context[key] = Object.getOwnPropertyNames(proto).reduce(function (obj, objKey) {
if (typeof proto[objKey] === 'function' && objKey !== 'constructor') {
var originalFunc = proto[objKey]
var originalFunc = proto[objKey].__ft_originFunc || proto[objKey]

@@ -60,4 +68,5 @@ obj[objKey] = function () {

})
return originalFunc.apply(extendedContext[key], arguments)
return originalFunc.apply(existingContextValue, arguments)
}
obj[objKey].__ft_originFunc = originalFunc
}

@@ -64,0 +73,0 @@

@@ -30,2 +30,3 @@ 'use strict'

};
const originalFunc = contextItem.foo
const execute = FunctionTree([

@@ -38,6 +39,7 @@ NodeDebuggerProvider(),

test.expect(1)
test.expect(2)
execute([
function funcA(context) {
test.notEqual(context.contextItem.foo, contextItem.foo)
test.notEqual(originalFunc, contextItem.foo)
test.equal(contextItem.foo.__ft_originFunc, originalFunc)
}

@@ -47,1 +49,21 @@ ])

}
module.exports['should wrap functions added to context'] = (test) => {
const contextItem = () => {};
const execute = FunctionTree([
NodeDebuggerProvider(),
ContextProvider({
contextItem
})
])
test.expect(2)
execute([
function funcA(context) {
test.notEqual(contextItem, context.contextItem)
test.equal(context.contextItem.__ft_originFunc, contextItem)
}
])
test.done()
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc