CPP   14

string.cpp

Guest on 20th May 2022 01:33:41 AM

  1. #include <nan.h>
  2. #include "string.h"
  3. #include "../create_string.h"
  4.  
  5. namespace SassTypes
  6. {
  7.   String::String(Sass_Value* v) : SassValueWrapper(v) {}
  8.  
  9.   Sass_Value* String::construct(const std::vector<v8::Local<v8::Value>> raw_val, Sass_Value **out) {
  10.     char const* value = "";
  11.  
  12.     if (raw_val.size() >= 1) {
  13.       if (!raw_val[0]->IsString()) {
  14.         return fail("Argument should be a string.", out);
  15.       }
  16.  
  17.       value = create_string(raw_val[0]);
  18.          *out = sass_make_string(value);
  19.         delete value;
  20.         return *out;
  21.  
  22.     } else {
  23.         return *out = sass_make_string(value);
  24.     }
  25.  
  26.   }
  27.  
  28.   void String::initPrototype(v8::Local<v8::FunctionTemplate> proto) {
  29.     Nan::SetPrototypeMethod(proto, "getValue", GetValue);
  30.     Nan::SetPrototypeMethod(proto, "setValue", SetValue);
  31.   }
  32.  
  33.   NAN_METHOD(String::GetValue) {
  34.     info.GetReturnValue().Set(Nan::New<v8::String>(sass_string_get_value(String::Unwrap<String>(info.This())->value)).ToLocalChecked());
  35.   }
  36.  
  37.   NAN_METHOD(String::SetValue) {
  38.     if (info.Length() != 1) {
  39.       return Nan::ThrowTypeError("Expected just one argument");
  40.     }
  41.  
  42.     if (!info[0]->IsString()) {
  43.       return Nan::ThrowTypeError("Supplied value should be a string");
  44.     }
  45.  
  46.     sass_string_set_value(String::Unwrap<String>(info.This())->value, create_string(info[0]));
  47.   }
  48. }

Raw Paste


Login or Register to edit or fork this paste. It's free.