Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4499317
test_stack_depth.cjs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_stack_depth.cjs
View Options
// Test that the this stack is properly managed across async boundaries
class StackTest {
constructor(name) {
this.name = name;
}
// Regular method that calls another with function arg
methodA(getArg) {
console.log('methodA: this.name = ' + this.name);
return this.methodB(getArg());
}
methodB(arg) {
console.log('methodB: this.name = ' + this.name + ', arg = ' + arg);
return this.name + ':' + arg;
}
// Method that returns a promise
asyncMethod() {
console.log('asyncMethod: this.name = ' + this.name);
return Promise.resolve(this.name);
}
}
function helperFunc() {
return 'helper';
}
const obj1 = new StackTest('obj1');
const obj2 = new StackTest('obj2');
console.log('=== Test 1: Synchronous nested calls ===');
const result1 = obj1.methodA(() => helperFunc());
console.log('Result: ' + result1);
console.log('\n=== Test 2: Async then sync ===');
obj1.asyncMethod().then((val) => {
console.log('In .then(), val = ' + val);
// Now do a sync call with function arg
const result = obj2.methodA(() => 'fromPromise');
console.log('After sync call: ' + result);
});
console.log('\n=== Test 3: Multiple objects interleaved ===');
obj1.methodA(() => {
obj2.methodB('nested');
return 'test';
});
console.log('\n=== All tests done ===');
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 3, 7:58 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
523869
Default Alt Text
test_stack_depth.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment