Welcome to mirror list, hosted at ThFree Co, Russian Federation.

string.cpp « sass_types « src « node-sass « node_modules - github.com/austingebauer/devise.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c6f2c48fca3aa58195d79df12407b27ce126f093 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <nan.h>
#include "string.h"
#include "../create_string.h"

namespace SassTypes
{
  String::String(Sass_Value* v) : SassValueWrapper(v) {}

  Sass_Value* String::construct(const std::vector<v8::Local<v8::Value>> raw_val, Sass_Value **out) {
    char const* value = "";

    if (raw_val.size() >= 1) {
      if (!raw_val[0]->IsString()) {
        return fail("Argument should be a string.", out);
      }

      value = create_string(raw_val[0]);
         *out = sass_make_string(value);
        delete value;
        return *out;

    } else {
        return *out = sass_make_string(value);
    }

  }

  void String::initPrototype(v8::Local<v8::FunctionTemplate> proto) {
    Nan::SetPrototypeMethod(proto, "getValue", GetValue);
    Nan::SetPrototypeMethod(proto, "setValue", SetValue);
  }

  NAN_METHOD(String::GetValue) {
    info.GetReturnValue().Set(Nan::New<v8::String>(sass_string_get_value(String::Unwrap<String>(info.This())->value)).ToLocalChecked());
  }

  NAN_METHOD(String::SetValue) {
    if (info.Length() != 1) {
      return Nan::ThrowTypeError("Expected just one argument");
    }

    if (!info[0]->IsString()) {
      return Nan::ThrowTypeError("Supplied value should be a string");
    }

    sass_string_set_value(String::Unwrap<String>(info.This())->value, create_string(info[0]));
  }
}