Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google V8 JavaScript Engine - How to set a value to null?

Tags:

c++

node.js

v8

Using the V8 engine, how do I set a value to null? Basically I want to return a variable from a C++ addon to JavaScript, and the variable needs to be set to null under certain conditions.

like image 619
Justin Ethier Avatar asked Mar 22 '11 02:03

Justin Ethier


1 Answers

You can explicitly return null via v8::Null:

return scope.Close( Null() );

Also, it turns out that if a Value variable is declared, it is automatically assigned to undefined. For example, the following returns undefined back to JavaScript:

 HandleScope scope;
 Local<Value> result;
 ...

 return scope.Close(result);
like image 66
Justin Ethier Avatar answered Sep 28 '22 09:09

Justin Ethier