Fix ` g is not defined` issue

Variable `g` is not defined in the evaluation scope.
This commit is contained in:
Sergey Panpurin 2023-05-11 20:06:18 +03:00 committed by GitHub
parent 2f6dd870a6
commit 6657730950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -681,7 +681,7 @@ function createModelClassCtor(name, ModelBaseClass) {
// from a dynamically defined function. The solution is to
// create a dynamically defined factory function that accepts
// closure variables as arguments.
const factory = new Function('ModelBaseClass', `
const factory = new Function('ModelBaseClass', 'g', `
// every class can receive hash of data as optional param
return function ${name}(data, options) {
if (!(this instanceof ${name})) {
@ -693,7 +693,7 @@ function createModelClassCtor(name, ModelBaseClass) {
ModelBaseClass.apply(this, arguments);
};`);
return factory(ModelBaseClass);
return factory(ModelBaseClass, g);
} catch (err) {
// modelName is not a valid function/class name, e.g. 'grand-child'
// and our simple sanitization was not good enough.