0.0.10 • Published 6 years ago

shapeleak v0.0.10

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

shapeleak

Find subsequent changes in the shape (hidden-class) of your Objects which result in unoptimized code. If you don't know what we talking about I can recommend this article.

Requires Node 6.4+

Features

  • Print exact location of the vulnerability.
  • Can be applied to Factory, Object-Literal and objects instantiated by new.
  • Does not break existing code.

Example

const S = require('shapeleak')

// new

class A {
  constructor(name) {
    this.name = name
  }
}

A = S(A)

const a = new A('peter')
a.name = 'sandra'
a.name = 1
a.foo = 'bar'
delete a.name

// Factory

function build(name) {
  return {
    name
  }
}

build = S(build)

const b = build('peter')
b.name = 'sandra'
b.name = 1
b.foo = 'bar'
delete b.name

// Object literal

let c = Shaped({
  name: 'peter'
})

c.name = 'sandra'
c.name = 1
c.foo = 'bar'
delete b.name

Output

E:\Repositorys\shaped\example.js
  20:8  warn  - Property 'name' has change his type from 'string' to 'number'
  21:7  error - Property 'foo' was added to shape (name)
  22:1  error - Property 'name' was deleted from shape (name,foo)
  37:8  warn  - Property 'name' has change his type from 'string' to 'number'
  38:7  error - Property 'foo' was added to shape (name)
  39:1  error - Property 'name' was deleted from shape (name,foo)
  50:8  warn  - Property 'name' has change his type from 'string' to 'number'
  51:7  error - Property 'foo' was added to shape (name)
  52:1  error - Property 'name' was deleted from shape (foo)
0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago