duktape icon indicating copy to clipboard operation
duktape copied to clipboard

An issue about Error.prototype.toString

Open YaoHouyou opened this issue 3 years ago • 2 comments

Version

2.6.0

Overview

​ According to the ES 5.1 or 6, when the parameter in Error.prototype.toString.call() is a function, if the function name is not empty but the message is empty, the function name will be returned. However, duktape returned empty. So I think there may be a problem here.

Testcase

var NISLFuzzingFunc = function (e) {	
	return Error.prototype.toString.call(e);
};
var NISLParameter0 = function(){};
var NISLCallingResult = NISLFuzzingFunc(NISLParameter0);
print(NISLCallingResult);

Actual Results


Expected Results

NISLParameter0

YaoHouyou avatar Mar 03 '21 12:03 YaoHouyou

The function in the test is actually anonymous (empty name):

var NISLParameter0 = function(){};

Duktape doesn't automatically default the name of the function based on the assignment (i.e. name = NISLParameter0) which is post-ES5.1 behavior. So the function is anonymous:

duk> var NISLParameter0 = function(){};
= undefined
duk> NISLParameter0.name
= ""

If you give it a name explicitly:

var NISLFuzzingFunc = function (e) {	
	return Error.prototype.toString.call(e);
};
var NISLParameter0 = function NISLParameter0(){};
var NISLCallingResult = NISLFuzzingFunc(NISLParameter0);
print(NISLCallingResult);

The test prints:

NISLParameter0

svaarala avatar Mar 04 '21 20:03 svaarala

@svaarala Thank you for your reply. In addition, I would like to ask whether Duktape will support this feature in next versions?

YaoHouyou avatar Mar 05 '21 01:03 YaoHouyou