Skip to content

v0.2.52..v0.2.53 changeset ElementJs.cpp

Garret Voltz edited this page Feb 12, 2020 · 1 revision
diff --git a/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp b/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp
index 6d6e890..d2bb02a 100644
--- a/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp
+++ b/hoot-js/src/main/cpp/hoot/js/elements/ElementJs.cpp
@@ -22,7 +22,7 @@
  * This will properly maintain the copyright information. DigitalGlobe
  * copyrights will be updated automatically.
  *
- * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020 DigitalGlobe (http://www.digitalglobe.com/)
  */
 #include "ElementJs.h"
 
@@ -79,6 +79,8 @@ void ElementJs::_addBaseFunctions(Local<FunctionTemplate> tpl)
       FunctionTemplate::New(current, setStatusString));
   tpl->PrototypeTemplate()->Set(String::NewFromUtf8(current, "setTags"),
       FunctionTemplate::New(current, setTags));
+  tpl->PrototypeTemplate()->Set(String::NewFromUtf8(current, "setTag"),
+      FunctionTemplate::New(current, setTag));
   tpl->PrototypeTemplate()->Set(String::NewFromUtf8(current, "toJSON"),
       FunctionTemplate::New(current, toString));
   tpl->PrototypeTemplate()->Set(String::NewFromUtf8(current, "toString"),
@@ -241,7 +243,8 @@ void ElementJs::setTags(const FunctionCallbackInfo<Value>& args)
   if (!e)
   {
     args.GetReturnValue().Set(
-      current->ThrowException(HootExceptionJs::create(IllegalArgumentException("Unable to set tags on a const Element."))));
+      current->ThrowException(
+        HootExceptionJs::create(IllegalArgumentException("Unable to set tags on a const Element."))));
   }
   else
   {
@@ -251,6 +254,28 @@ void ElementJs::setTags(const FunctionCallbackInfo<Value>& args)
   }
 }
 
+void ElementJs::setTag(const FunctionCallbackInfo<Value>& args)
+{
+  Isolate* current = args.GetIsolate();
+  HandleScope scope(current);
+
+  ElementPtr e = ObjectWrap::Unwrap<ElementJs>(args.This())->getElement();
+
+  if (!e)
+  {
+    args.GetReturnValue().Set(
+      current->ThrowException(
+        HootExceptionJs::create(IllegalArgumentException("Unable to set tag on a const Element."))));
+  }
+  else
+  {
+    const QString tagKey = toCpp<QString>(args[0]);
+    const QString tagVal = toCpp<QString>(args[1]);
+    e->setTag(tagKey, tagVal);
+    args.GetReturnValue().SetUndefined();
+  }
+}
+
 void ElementJs::toString(const FunctionCallbackInfo<Value>& args)
 {
   Isolate* current = args.GetIsolate();
Clone this wiki locally