SassImportList CustomImporterBridge::post_process_return_value(v8::Local<v8::Value> returned_value) const {
  SassImportList imports = 0;
  Nan::HandleScope scope;

  if (returned_value->IsArray()) {
    v8::Local<v8::Array> array = returned_value.As<v8::Array>();

    imports = sass_make_import_list(array->Length());

    for (size_t i = 0; i < array->Length(); ++i) {
      v8::Local<v8::Value> value = Nan::Get(array, static_cast<uint32_t>(i)).ToLocalChecked();

      if (!value->IsObject()) {
        auto entry = sass_make_import_entry(0, 0, 0);
        sass_import_set_error(entry, "returned array must only contain object literals", -1, -1);
        continue;
      }

      v8::Local<v8::Object> object = value.As<v8::Object>();

      if (value->IsNativeError()) {
        char* message = create_string(Nan::Get(object, Nan::New<v8::String>("message").ToLocalChecked()));

        imports[i] = sass_make_import_entry(0, 0, 0);

        sass_import_set_error(imports[i], message, -1, -1);
      }
      else {
        imports[i] = get_importer_entry(object);
      }
    }
  }
  else if (returned_value->IsNativeError()) {
    imports = sass_make_import_list(1);
    v8::Local<v8::Object> object = returned_value.As<v8::Object>();
    char* message = create_string(Nan::Get(object, Nan::New<v8::String>("message").ToLocalChecked()));

    imports[0] = sass_make_import_entry(0, 0, 0);

    sass_import_set_error(imports[0], message, -1, -1);
  }
  else if (returned_value->IsObject()) {
    imports = sass_make_import_list(1);
    imports[0] = get_importer_entry(returned_value.As<v8::Object>());
  }

  return imports;
}
Beispiel #2
0
result_t util_base::isNativeError(v8::Local<v8::Value> v, bool& retVal)
{
    retVal = v->IsNativeError();
    return 0;
}