My favorites | Sign in
v8
Project Home Downloads Wiki Issues Source Code Search
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 38: need more "const correctness"
3 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  christia...@gmail.com
Closed:  Oct 2008


Sign in to add a comment
 
Reported by pete.gon...@gmail.com, Sep 7, 2008
In general, it would be nice if the API had more "const correctness". As an
example, consider Value::IsString. Because it is not declared 'const', it
causes contortions in client code, some of which are slower and less safe
than they might be. As an illustration, consider:

static void write (Local <Value> & value)
// 'value' cannot be declared const
{
	if (value->IsString ( ))
	{
		// blah blah
	}
}

static Handle <Value> writeCallback (const Arguments & arguments)
{
	uint32_t argumentCount (arguments.Length ( ));

	if (argumentCount)
	{
		uint32_t argumentIndex (0);

		do
		{
			// necessary to create a temporary copy
			// in case it's modified, even though we
			// know no one will ever modify it

			Local <Value> value (arguments [argumentIndex]);
			write (value);
		}
		while (++argumentIndex < argumentCount);
	}

	return Undefined ( );
}

Retroactively adding const-correctness sometimes has far-reaching
implications, but most if not all changes are low-risk monkey-work.
Sep 8, 2008
#3 pete.gon...@gmail.com
 Issue 48  contains additional detail and references.
Oct 22, 2008
Project Member #4 christia...@gmail.com


Status: Assigned
Owner: christian.plesner.hansen
Oct 23, 2008
Project Member #5 christia...@gmail.com
I've added const to the remaining methods in v8.h the belong to classes that may be 
passed by const reference.  Note that handles should always be passed by value.  
Rather than use a 'const Local<Value>& value' you should be using 'Local<Value>' 
which circumvents this issue.
Status: Fixed
Oct 23, 2008
#6 nicolas....@gmail.com
Is it legal to do this?

static void write (Local <const Value> value)
{
    if (value->IsString ( ))
    {
        // blah blah
    }
}

Oct 23, 2008
Project Member #7 christia...@gmail.com
It probably is legal but it's not meaningful.
Sign in to add a comment

Powered by Google Project Hosting