Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 247201

Summary: [validation] bugs in JavaScript objects validation
Product: [WebTools] JSDT Reporter: Maciej Cencora <m.cencora>
Component: GeneralAssignee: Chris Jaun <cmjaun>
Status: RESOLVED FIXED QA Contact: Phil Berkland <berkland>
Severity: major    
Priority: P3 CC: cmjaun, thatnitind
Version: unspecified   
Target Milestone: 3.2 M6   
Hardware: PC   
OS: Linux   
Whiteboard:
Bug Depends on: 296001, 296934    
Bug Blocks:    
Attachments:
Description Flags
patch none

Description Maciej Cencora CLA 2008-09-12 17:04:41 EDT
Build ID: I20080617-2000

Steps To Reproduce:
Put the JS code from "More information" into the editor window.
Comments contain informations about which validations are wrong.

More information:
function Car() {
	this.color = 'red';
	this.Move = function() { return "I'm moving"; };
};
Car.Stop = function() { return "I'm not moving"; };
Car.engine = 'diesel';

var o = '';
var c = '';
o += 'Car class:<br />';
c = Car.Move; //wrong, shows no error
o += 'Move => '+ Car.Move() +'<br />'; //correct, shows error that cannot make static reference to the non-static function
o += 'Move => '+ Car.Move.toString() +'<br />'; //wrong, shows no error
o += 'color => '+Car.color.prototype+'<br />'; //wrong, shows no warning
o += 'Stop => '+Car.Stop()+'<br />'; //correct
o += 'Stop => '+Car.Stop.toString()+'<br />'; //correct, but receives runtime exception from type proposal after putting dot after Car.Stop
o += 'engine => '+Car.engine.prototype+'<br />'; //correct

o += '<br />Car object:<br />';
var p = new Car();
o += 'Move => '+p.Move()+'<br />'; // correct
o += 'color => '+p.color.prototype+'<br />'; // correct
c = p.Stop; // wrong, shows no error
o += 'Stop => '+p.Stop()+'<br />'; //correct, but I think it should be error instead of warning
o += 'Stop => '+p.Stop.toString()+'<br />'; //wrong, shows no error, and the same runtime exception as previously
o += 'engine => '+p.engine+'<br />'; //correct, but I think it should be error instead of warning
o += 'engine => '+p.engine.prototype+'<br />'; //wrong, shows no error

// Here are the results for variable that is a copy (reference) of class Car
// results are all wrong
o += '<br />MyCar class:<br />';
var MyCar = Car;
c = MyCar.Move; // wrong, warning says "Move cannot be resolved or is not a field", should be error that cannot access static ...
o += 'Move => '+MyCar.Move()+'<br />'; // wrong, error says "The function Move is undefined for the type Function", should be error that cannot access static ...
o += 'color => '+MyCar.color+'<br />'; // wrong, warning says "Move cannot be resolved or is not a field", should be error that cannot access static ...
o += 'Stop => '+MyCar.Stop+'<br />'; // wrong, warning says "Move cannot be resolved or is not a field". should be no error
o += 'Stop => '+MyCar.Stop()+'<br />';  // wrong, error says "The function Stop is undefined for the type Function", should be no error
o += 'engine => '+MyCar.engine+'<br />'; // wrong, warning says "engine cannot be resolved or is not a field". should be no error

o += '<br />MyCar object:<br />';
var r = new MyCar();
// here all results, are wrong, because nothing is checked. no errors and warnings for all fields
o += 'Move => '+r.Move+'<br />';
o += 'Move => '+r.Move()+'<br />';
o += 'color => '+r.color+'<br />';
o += 'Stop => '+r.Stop+'<br />';
o += 'Stop => '+r.Stop()+'<br />';
o += 'engine => '+r.engine+'<br />';
o += 'engine => '+r.engine()+'<br />';
o += 'engine => '+r.not_existing_field+'<br />';
Comment 1 Phil Berkland CLA 2008-09-30 16:46:20 EDT
My understanding reading the ECMAScript spec is the .prototype and .toString() are available for all objects, so that is why there are no errors show for those cases.
Comment 2 Chris Jaun CLA 2009-08-03 14:34:01 EDT
Update to the sample code to remove things that are now fixed and some duplicate problems. What is left below needs to be fixed.

function Car() {
        this.color = 'red';
        this.Move = function() {return "";};
};
Car.Stop = function() {return "";};
Car.engine = 'diesel';

var o = '';
var c = '';

o += 'Car class:<br />';
o += 'color => '+Car.color.prototype+'<br />'; //wrong, shows no warning

o += '<br />Car object:<br />';
var p = new Car();
o += 'Stop => '+p.Stop()+'<br />'; //correct, but I think it should be error instead of warning
o += 'engine => '+p.engine+'<br />'; //correct, but I think it should be error instead of warning
o += 'engine => '+p.engine.prototype+'<br />'; //wrong, shows no error

//results are all wrong
o += '<br />MyCar class:<br />';
var MyCar = Car;
c = MyCar.Move; // wrong, warning says "Move cannot be resolved or is not a field", should be error that cannot access static ...
o += 'Move => '+MyCar.Move()+'<br />'; // wrong, error says "The function Move is undefined for the type Function", should be error that cannot access static
o += 'Stop => '+MyCar.Stop+'<br />'; // wrong, warning says "Move cannot be resolved or is not a field". should be no error
o += 'engine => '+MyCar.engine+'<br />'; // wrong, warning says "engine cannot be resolved or is not a field". should be no error

o += '<br />MyCar object:<br />';
var r = new MyCar();
// here all results, are wrong, because nothing is checked. no errors and warnings for all fields
o += 'Stop => '+r.Stop+'<br />';
o += 'Stop => '+r.Stop()+'<br />';
o += 'engine => '+r.engine+'<br />';
o += 'engine => '+r.engine()+'<br />';
Comment 3 Chris Jaun CLA 2009-09-15 10:59:42 EDT
Categorizing JSDT bugzillas for planning purposes.
Comment 4 Chris Jaun CLA 2010-03-02 13:40:44 EST
Created attachment 160664 [details]
patch
Comment 5 Chris Jaun CLA 2010-03-02 13:41:36 EST
Fixes checked in.