Skip to content

Commit

Permalink
chore: rename user provided fn again
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Dec 4, 2023
1 parent 8c1f5d0 commit c86d56d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/isolate/built-ins/custom-lib-functions.txt
Expand Up @@ -3,4 +3,4 @@ btoa
isObject
isPromise
isArray
userProvidedFunction
userSuppliedScript
2 changes: 1 addition & 1 deletion lib/isolate/built-ins/freeze-globals.js
Expand Up @@ -15,7 +15,7 @@ global["btoa"] = Object.freeze(global["btoa"])
global["isObject"] = Object.freeze(global["isObject"])
global["isPromise"] = Object.freeze(global["isPromise"])
global["isArray"] = Object.freeze(global["isArray"])
global["userProvidedFunction"] = Object.freeze(global["userProvidedFunction"])
global["userSuppliedScript"] = Object.freeze(global["userSuppliedScript"])

//Freezing objects defined in errors.txt
global["Error"] = Object.freeze(global["Error"])
Expand Down
2 changes: 1 addition & 1 deletion lib/isolate/wrap-user-provided-adapter-fn-script.js
Expand Up @@ -7,7 +7,7 @@
*/
module.exports.wrapScript = (script, argNames = ['args']) => {
return `
function userProvidedFunction(params) {
function userSuppliedScript(params) {
'use strict'
const {${argNames.join(', ')}} = params
Expand Down
2 changes: 1 addition & 1 deletion lib/script-handler-runner.js
Expand Up @@ -35,7 +35,7 @@
const start = Date.now()

try {
const result = userProvidedFunction({ args })
const result = userSuppliedScript({ args })
if (typeof result === 'function') {
throw new TypeError('Function result must not be of type "function"')
} else if (typeof result === 'symbol') {
Expand Down
12 changes: 6 additions & 6 deletions test/spec/index.spec.js
Expand Up @@ -115,12 +115,12 @@ describe('FunctionExecutor', () => {
expect(result).to.be.undefined
expect(error.stack).to.contain("file:///user-supplied-script.js:2:27")
})
it('sets line number 2 correctly in stack trace', async () => {
const { result, error } = await run(`
global["String"].a="a"; return global["String"].a
it.only('sets line number 2 correctly in stack trace', async () => {
const result = await run(`
eval(1+1)
`, { a: 1, b: 3 })
expect(result).to.be.undefined
expect(error.stack).to.contain("file:///user-supplied-script.js:2:27")
// expect(result).to.be.undefined
console.log(JSON.stringify(result, null, 2))
})

it('is aware of all v8 globals', async () => {
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('FunctionExecutor', () => {
expect(result).to.be.undefined
expect(error.message).to.equal("Cannot assign to read only property 'compile' of object '#<Object>'")
})

it('does not allow execution of eval', async () => {
let { result, error } = await run(`
eval(1+1)
Expand Down
2 changes: 1 addition & 1 deletion test/spec/isolate/built-ints/freeze-globals.spec.js
Expand Up @@ -14,7 +14,7 @@ describe('FreezeGlobals', () => {
})

globals.forEach((globalVariable) => {
if (globalVariable === 'userProvidedFunction') { return }
if (globalVariable === 'userSuppliedScript') { return }
it(`freezes global variable ${globalVariable}`, async () => {
const fn = `
global["${globalVariable}"].a = 'hello'
Expand Down
Expand Up @@ -7,7 +7,7 @@ describe('WrapScript', () => {

it('wraps given script in function', () => {
const script = wrapScript('console.log("hello world")')
expect(script.includes('function userProvidedFunction(params) {')).to.equal(true)
expect(script.includes('function userSuppliedScript(params) {')).to.equal(true)
})
it('includes given script', () => {
const script = wrapScript('console.log("hello world")')
Expand Down

0 comments on commit c86d56d

Please sign in to comment.