Socket
Socket
Sign inDemoInstall

sinon

Package Overview
Dependencies
Maintainers
4
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinon - npm Package Compare versions

Comparing version 11.0.0 to 11.1.0

lib/sinon/promise.js

9

CHANGELOG.md
11.1.0 / 2021-05-25
==================
* Add sinon.promise() implementation (#2369)
* Set wrappedMethod on getters/setters (#2378)
* [Docs] Update fake-server usage & descriptions (#2365)
* Fake docs improvement (#2360)
* Update nise to 5.1.0 (fixed #2318)
11.0.0 / 2021-05-24

@@ -3,0 +12,0 @@ ==================

4

lib/sinon.js

@@ -11,2 +11,3 @@ "use strict";

var stub = require("./sinon/stub");
var promise = require("./sinon/promise");

@@ -42,2 +43,5 @@ var apiMethods = {

},
// fake promise
promise: promise,
};

@@ -44,0 +48,0 @@

@@ -94,2 +94,3 @@ "use strict";

fake.callbackAsync = false;
fake.fakeFn = undefined;
},

@@ -103,2 +104,3 @@

fake.callbackAsync = false;
fake.fakeFn = undefined;
},

@@ -112,2 +114,3 @@

fake.callbackAsync = false;
fake.fakeFn = undefined;
},

@@ -121,2 +124,3 @@

fake.callbackAsync = false;
fake.fakeFn = undefined;
},

@@ -130,2 +134,3 @@

fake.callbackAsync = false;
fake.fakeFn = undefined;
},

@@ -132,0 +137,0 @@

108

lib/sinon/util/core/wrap-method.js

@@ -8,2 +8,3 @@ "use strict";

var valueToString = require("@sinonjs/commons").valueToString;
var push = require("@sinonjs/commons").prototypes.array.push;

@@ -25,2 +26,17 @@ function isFunction(obj) {

function getAccessor(object, property, method) {
var accessors = ["get", "set"];
var descriptor = getPropertyDescriptor(object, property);
for (var i = 0; i < accessors.length; i++) {
if (
descriptor[accessors[i]] &&
descriptor[accessors[i]].name === method.name
) {
return accessors[i];
}
}
return null;
}
// Cheap way to detect if we have ES5 support.

@@ -72,4 +88,12 @@ var hasES5Support = "keys" in Object;

var error, wrappedMethod, i, wrappedMethodDesc;
var error,
wrappedMethods,
wrappedMethod,
i,
wrappedMethodDesc,
target,
accessor;
wrappedMethods = [];
function simplePropertyAssignment() {

@@ -115,2 +139,3 @@ wrappedMethod = object[property];

checkWrappedMethod(wrappedMethod);
push(wrappedMethods, wrappedMethod);
}

@@ -136,19 +161,37 @@

extend.nonEnum(method, {
displayName: property,
extendObjectWithWrappedMethods();
wrappedMethod: wrappedMethod,
function extendObjectWithWrappedMethods() {
for (i = 0; i < wrappedMethods.length; i++) {
accessor = getAccessor(object, property, wrappedMethods[i]);
target = accessor ? method[accessor] : method;
extend.nonEnum(target, {
displayName: property,
wrappedMethod: wrappedMethods[i],
// Set up an Error object for a stack trace which can be used later to find what line of
// code the original method was created on.
stackTraceError: new Error("Stack Trace for original"),
// Set up an Error object for a stack trace which can be used later to find what line of
// code the original method was created on.
stackTraceError: new Error("Stack Trace for original"),
restore: function () {
// For prototype properties try to reset by delete first.
// If this fails (ex: localStorage on mobile safari) then force a reset
// via direct assignment.
restore: restore,
});
target.restore.sinon = true;
if (!hasES5Support) {
mirrorProperties(target, wrappedMethod);
}
}
}
function restore() {
accessor = getAccessor(object, property, this.wrappedMethod);
var descriptor;
// For prototype properties try to reset by delete first.
// If this fails (ex: localStorage on mobile safari) then force a reset
// via direct assignment.
if (accessor) {
if (!owned) {
// In some cases `delete` may throw an error
try {
delete object[property];
// In some cases `delete` may throw an error
delete object[property][accessor];
} catch (e) {} // eslint-disable-line no-empty

@@ -158,9 +201,11 @@ // For native code functions `delete` fails without throwing an error

} else if (hasES5Support) {
Object.defineProperty(object, property, wrappedMethodDesc);
descriptor = getPropertyDescriptor(object, property);
descriptor[accessor] = wrappedMethodDesc[accessor];
Object.defineProperty(object, property, descriptor);
}
if (hasES5Support) {
var descriptor = getPropertyDescriptor(object, property);
if (descriptor && descriptor.value === method) {
object[property] = wrappedMethod;
descriptor = getPropertyDescriptor(object, property);
if (descriptor && descriptor.value === target) {
object[property][accessor] = this.wrappedMethod;
}

@@ -170,13 +215,26 @@ } else {

// via direct assignment.
if (object[property] === method) {
object[property] = wrappedMethod;
if (object[property][accessor] === target) {
object[property][accessor] = this.wrappedMethod;
}
}
},
});
} else {
if (!owned) {
try {
delete object[property];
} catch (e) {} // eslint-disable-line no-empty
} else if (hasES5Support) {
Object.defineProperty(object, property, wrappedMethodDesc);
}
method.restore.sinon = true;
if (!hasES5Support) {
mirrorProperties(method, wrappedMethod);
if (hasES5Support) {
descriptor = getPropertyDescriptor(object, property);
if (descriptor && descriptor.value === target) {
object[property] = this.wrappedMethod;
}
} else {
if (object[property] === target) {
object[property] = this.wrappedMethod;
}
}
}
}

@@ -183,0 +241,0 @@

@@ -18,3 +18,3 @@ {

],
"version": "11.0.0",
"version": "11.1.0",
"homepage": "https://sinonjs.org/",

@@ -79,3 +79,3 @@ "author": "Christian Johansen",

"diff": "^5.0.0",
"nise": "^5.0.4",
"nise": "^5.1.0",
"supports-color": "^8.1.1"

@@ -82,0 +82,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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