Unverified Commit c53ee73c authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Forbid `this` and `arguments` in server functions (#73059)

Accessing `this` or `arguments` in server functions is not allowed. With
this PR, we are now emitting build errors in this case.

---------
Co-authored-by: 's avatarJanka Uryga <lolzatu2@gmail.com>
parent 2161d8c0
async function a() {
'use cache'
// this is not allowed here
this.foo()
// arguments is not allowed here
console.log(arguments)
const b = async () => {
// this is not allowed here
this.foo()
// arguments is not allowed here
console.log(arguments)
}
function c() {
// this is allowed here
this.foo()
// arguments is allowed here
console.log(arguments)
const d = () => {
// this is allowed here
this.foo()
// arguments is allowed here
console.log(arguments)
}
const e = async () => {
'use server'
// this is not allowed here
this.foo()
// arguments is not allowed here
console.log(arguments)
}
}
}
export const api = {
result: null,
product: {
async fetch() {
'use cache'
// this is not allowed here
this.result = await fetch('https://example.com').then((res) => res.json())
// arguments is not allowed here
console.log(arguments)
},
},
}
/*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ /* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","8069348c79fce073bae2f70f139565a2fda1c74c74":"$$RSC_SERVER_CACHE_2","80951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function e() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, async function a() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
const b = async ()=>{
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
function c() {
// this is allowed here
this.foo();
// arguments is allowed here
console.log(arguments);
const d = ()=>{
// this is allowed here
this.foo();
// arguments is allowed here
console.log(arguments);
};
const e = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
}
});
Object.defineProperty($$RSC_SERVER_CACHE_1, "name", {
"value": "a",
"writable": false
});
var a = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null);
export var $$RSC_SERVER_CACHE_2 = $$cache__("default", "8069348c79fce073bae2f70f139565a2fda1c74c74", 0, /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ async function fetch1() {
// this is not allowed here
this.result = await fetch('https://example.com').then((res)=>res.json());
// arguments is not allowed here
console.log(arguments);
});
Object.defineProperty($$RSC_SERVER_CACHE_2, "name", {
"value": "fetch",
"writable": false
});
export const api = {
result: null,
product: {
fetch: registerServerReference($$RSC_SERVER_CACHE_2, "8069348c79fce073bae2f70f139565a2fda1c74c74", null)
}
};
x "use cache" functions cannot use `this`.
|
,-[input.js:4:1]
3 | // this is not allowed here
4 | this.foo()
: ^^^^
5 | // arguments is not allowed here
`----
x "use cache" functions cannot use `arguments`.
|
,-[input.js:6:1]
5 | // arguments is not allowed here
6 | console.log(arguments)
: ^^^^^^^^^
`----
x "use cache" functions cannot use `this`.
|
,-[input.js:10:1]
9 | // this is not allowed here
10 | this.foo()
: ^^^^
11 | // arguments is not allowed here
`----
x "use cache" functions cannot use `arguments`.
|
,-[input.js:12:1]
11 | // arguments is not allowed here
12 | console.log(arguments)
: ^^^^^^^^^
13 | }
`----
x Server Actions cannot use `this`.
|
,-[input.js:31:1]
30 | // this is not allowed here
31 | this.foo()
: ^^^^
32 | // arguments is not allowed here
`----
x Server Actions cannot use `arguments`.
|
,-[input.js:33:1]
32 | // arguments is not allowed here
33 | console.log(arguments)
: ^^^^^^^^^
34 | }
`----
x "use cache" functions cannot use `this`.
|
,-[input.js:45:1]
44 | // this is not allowed here
45 | this.result = await fetch('https://example.com').then((res) => res.json())
: ^^^^
46 | // arguments is not allowed here
`----
x "use cache" functions cannot use `arguments`.
|
,-[input.js:47:1]
46 | // arguments is not allowed here
47 | console.log(arguments)
: ^^^^^^^^^
48 | },
`----
'use cache'
// not exported!
async function a() {
// this is allowed here
this.foo()
// arguments is allowed here
console.log(arguments)
const b = async () => {
'use server'
// this is not allowed here
this.foo()
// arguments is not allowed here
console.log(arguments)
}
}
export const obj = {
foo() {
return 42
},
bar() {
// this is allowed here
this.foo()
// arguments is allowed here
console.log(arguments)
},
}
/* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function b() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
// not exported!
async function a() {
// this is allowed here
this.foo();
// arguments is allowed here
console.log(arguments);
const b = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
}
export const obj = {
foo () {
return 42;
},
bar () {
// this is allowed here
this.foo();
// arguments is allowed here
console.log(arguments);
}
};
x Server Actions cannot use `this`.
|
,-[input.js:13:1]
12 | // this is not allowed here
13 | this.foo()
: ^^^^
14 | // arguments is not allowed here
`----
x Server Actions cannot use `arguments`.
|
,-[input.js:15:1]
14 | // arguments is not allowed here
15 | console.log(arguments)
: ^^^^^^^^^
16 | }
`----
'use cache'
// exported!
export async function a() {
// this is not allowed here
this.foo()
// arguments is not allowed here
console.log(arguments)
const b = async () => {
// this is not allowed here
this.foo()
// arguments is not allowed here
console.log(arguments)
}
function c() {
// this is allowed here
this.foo()
// arguments is allowed here
console.log(arguments)
const d = () => {
// this is allowed here
this.foo()
// arguments is allowed here
console.log(arguments)
}
const e = async () => {
'use server'
// this is not allowed here
this.foo()
// arguments is not allowed here
console.log(arguments)
}
}
}
/* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0","80951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function e() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "80951c375b4a6a6e89d67b743ec5808127cfde405d", 0, /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ async function a() {
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
const b = async ()=>{
// this is not allowed here
this.foo();
// arguments is not allowed here
console.log(arguments);
};
function c() {
// this is allowed here
this.foo();
// arguments is allowed here
console.log(arguments);
const d = ()=>{
// this is allowed here
this.foo();
// arguments is allowed here
console.log(arguments);
};
const e = registerServerReference($$RSC_SERVER_ACTION_0, "006a88810ecce4a4e8b59d53b8327d7e98bbf251d7", null);
}
});
Object.defineProperty($$RSC_SERVER_CACHE_1, "name", {
"value": "a",
"writable": false
});
// exported!
export var a = registerServerReference($$RSC_SERVER_CACHE_1, "80951c375b4a6a6e89d67b743ec5808127cfde405d", null);
x "use cache" functions cannot use `this`.
|
,-[input.js:6:1]
5 | // this is not allowed here
6 | this.foo()
: ^^^^
7 | // arguments is not allowed here
`----
x "use cache" functions cannot use `arguments`.
|
,-[input.js:8:1]
7 | // arguments is not allowed here
8 | console.log(arguments)
: ^^^^^^^^^
`----
x "use cache" functions cannot use `this`.
|
,-[input.js:12:1]
11 | // this is not allowed here
12 | this.foo()
: ^^^^
13 | // arguments is not allowed here
`----
x "use cache" functions cannot use `arguments`.
|
,-[input.js:14:1]
13 | // arguments is not allowed here
14 | console.log(arguments)
: ^^^^^^^^^
15 | }
`----
x Server Actions cannot use `this`.
|
,-[input.js:33:1]
32 | // this is not allowed here
33 | this.foo()
: ^^^^
34 | // arguments is not allowed here
`----
x Server Actions cannot use `arguments`.
|
,-[input.js:35:1]
34 | // arguments is not allowed here
35 | console.log(arguments)
: ^^^^^^^^^
36 | }
`----
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment