Skip to content

Commit

Permalink
Merge pull request mobxjs#281 from pioh/patch-1
Browse files Browse the repository at this point in the history
Remove usage of eval to support usage of CSP self
  • Loading branch information
mattiamanzati authored Aug 1, 2017
2 parents 1781649 + 46fdd8c commit 2c4595d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/types/complex-types/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export class ObjectType extends ComplexType<any, any> {
if (!/^\w[\w\d_]*$/.test(name)) fail(`Typename should be a valid identifier: ${name}`)
// fancy trick to get a named function...., http://stackoverflow.com/questions/5905492/dynamic-function-name-in-javascript
// Although object.defineProperty on a real function could also be used, that name is not used everywhere, for example when logging an object to the Chrome console, so this works better:
this.modelConstructor = new Function(`return function ${name} (){}`)()
this.modelConstructor = class { }
Object.defineProperty(this.modelConstructor, "name", {
value: name,
writable: false
})
this.modelConstructor.prototype.toString = objectTypeToString
this.parseModelProps()
this.forAllProps(prop => prop.initializePrototype(this.modelConstructor.prototype))
Expand Down

0 comments on commit 2c4595d

Please sign in to comment.