Initial commit
[yaffs-website] / node_modules / node-sass / src / sass_types / null.cpp
1 #include <nan.h>
2 #include "null.h"
3
4 namespace SassTypes
5 {
6   Nan::Persistent<v8::Function> Null::constructor;
7   bool Null::constructor_locked = false;
8
9   Null::Null() {}
10
11   Null& Null::get_singleton() {
12     static Null singleton_instance;
13     return singleton_instance;
14   }
15
16   v8::Local<v8::Function> Null::get_constructor() {
17     Nan::EscapableHandleScope scope;
18     v8::Local<v8::Function> conslocal;
19     if (constructor.IsEmpty()) {
20       v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
21
22       tpl->SetClassName(Nan::New("SassNull").ToLocalChecked());
23       tpl->InstanceTemplate()->SetInternalFieldCount(1);
24
25       conslocal = Nan::GetFunction(tpl).ToLocalChecked();
26       constructor.Reset(conslocal);
27
28       get_singleton().js_object.Reset(Nan::NewInstance(conslocal).ToLocalChecked());
29       Nan::SetInternalFieldPointer(Nan::New(get_singleton().js_object), 0, &get_singleton());
30       Nan::Set(conslocal, Nan::New("NULL").ToLocalChecked(), Nan::New(get_singleton().js_object));
31
32       constructor_locked = true;
33     } else {
34       conslocal = Nan::New(constructor);
35     }
36
37     return scope.Escape(conslocal);
38   }
39
40   Sass_Value* Null::get_sass_value() {
41     return sass_make_null();
42   }
43
44   v8::Local<v8::Object> Null::get_js_object() {
45     return Nan::New(this->js_object);
46   }
47
48   NAN_METHOD(Null::New) {
49
50     if (info.IsConstructCall()) {
51       if (constructor_locked) {
52         return Nan::ThrowTypeError("Cannot instantiate SassNull");
53       }
54     }
55     else {
56       info.GetReturnValue().Set(get_singleton().get_js_object());
57     }
58   }
59 }