Exemplo n.º 1
0
bool QuaternionValidate(Handle<Object>& src) {
    return (
        src->Has(JS_STRING(x)) && NumericValidate(src->Get(JS_STRING(x))) &&
        src->Has(JS_STRING(y)) && NumericValidate(src->Get(JS_STRING(y))) &&
        src->Has(JS_STRING(z)) && NumericValidate(src->Get(JS_STRING(z))) &&
        src->Has(JS_STRING(w)) && NumericValidate(src->Get(JS_STRING(w)))
    );
}
Exemplo n.º 2
0
   Handle<Value> SCROpenWindow(const Arguments& args)
   {

      osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
      osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);

      traits->windowDecoration = true;
      traits->doubleBuffer = true;
      traits->sharedContext = 0;

      if(args.Length() > 1)
      {
         Handle<Object> traitsin = Handle<Object>::Cast(args[1]);
         if(traitsin->Has(String::New("x"))) traits->x = traitsin->Get(String::New("x"))->Int32Value();
         if(traitsin->Has(String::New("y"))) traits->y = traitsin->Get(String::New("y"))->Int32Value();
         if(traitsin->Has(String::New("width"))) traits->width = traitsin->Get(String::New("width"))->Int32Value();
         if(traitsin->Has(String::New("height"))) traits->height = traitsin->Get(String::New("height"))->Int32Value();
         if(traitsin->Has(String::New("windowDecoration"))) traits->windowDecoration = traitsin->Get(String::New("windowDecoration"))->BooleanValue();
         if(traitsin->Has(String::New("hostName"))) traits->hostName = ToStdString(traitsin->Get(String::New("hostName")));
         if(traitsin->Has(String::New("displayNum"))) traits->displayNum = traitsin->Get(String::New("displayNum"))->Int32Value();
         if(traitsin->Has(String::New("screenNum"))) traits->screenNum = traitsin->Get(String::New("screenNum"))->Int32Value();
         if(traitsin->Has(String::New("vsync"))) traits->vsync = traitsin->Get(String::New("vsync"))->BooleanValue();
      }

      
      unsigned int contextid;
      // TODO how to pass traits???
      //dtEntityOSG::OSGWindowInterface* wface = static_cast<dtEntityOSG::OSGWindowInterface*>(dtEntity::GetWindowInterface());
      //wface->SetTraits(traits);
      bool success = dtEntity::GetWindowInterface()->OpenWindow(ToStdString(args[0]), contextid);
      assert(success);
      return Uint32::New(contextid);
   }
Exemplo n.º 3
0
int SerializePart(google::protobuf::Message *message, Handle<Object> subj) {
	NanScope();

	// get a reflection
	const Reflection *r = message->GetReflection();
	const Descriptor *d = message->GetDescriptor();
	
	// build a list of required properties
	vector<string> required;
	for (int i = 0; i < d->field_count(); i++) {
		const FieldDescriptor *field = d->field(i);
		if (field->is_required())
			required.push_back(field->name());
	}

	// build a reflection
	// get properties of passed object
	Local<Array> properties = subj->GetPropertyNames();
	uint32_t len = properties->Length();
	
	// check that all required properties are present
	for (uint32_t i = 0; i < required.size(); i++) {
		Handle<String> key = String::New(required.at(i).c_str());
		if (!subj->Has(key))
			return -1;
	}

	for (uint32_t i = 0; i < len; i++) {
		Local<Value> property = properties->Get(i);
		Local<String> property_s = property->ToString();

		if (*property_s == NULL)
			continue;

		String::Utf8Value temp(property);
		std::string propertyName = std::string(*temp);

		const FieldDescriptor *field = d->FindFieldByName(propertyName);
		if (field == NULL) continue;

		Local<Value> val = subj->Get(property);

		if (field->is_repeated()) {
			if (!val->IsArray())
				continue;

			Handle<Array> array = val.As<Array>();
			int len = array->Length();

			for (int i = 0; i < len; i++)
				SerializeField(message, r, field, array->Get(i));

		} else {
			SerializeField(message, r, field, val);
		}
	}
	
	return 0;
}
Exemplo n.º 4
0
static gboolean
gum_v8_flags_get (Handle<Object> flags,
                  const gchar * name,
                  GumV8Core * core)
{
  Local<String> key (String::NewFromUtf8 (core->isolate, name));
  return flags->Has (key) && flags->Get (key)->ToBoolean ()->BooleanValue ();
}
Exemplo n.º 5
0
  void RegisterNameSpace(const char* ns, Handle<Value> nsExports)
  {
    HandleScope scope;
    Handle<Object> global = Context::GetCurrent()->Global();
    if (!global->Has(String::NewSymbol("__winRtNamespaces__")))
    {
      global->Set(String::NewSymbol("__winRtNamespaces__"), Object::New(), PropertyAttribute::DontEnum) ;
    }

    Handle<Object> nsObject = global->Get(String::NewSymbol("__winRtNamespaces__")).As<Object>();
    nsObject->Set(String::NewSymbol(ns), nsExports);
  }
Exemplo n.º 6
0
void
V8Context::fill_prototype(Handle<Object> prototype, HV* stash) {
    HE *he;
    while (he = hv_iternext(stash)) {
        SV *key = HeSVKEY_force(he);
        Local<String> name = String::New(SvPV_nolen(key));

        if (prototype->Has(name))
            continue;

        prototype->Set(name, (new PerlMethodData(this, SvPV_nolen(key)))->object);
    }
}
Exemplo n.º 7
0
void
V8Context::fill_prototype_stash(Handle<Object> prototype, HV* stash) {
    HE *he;
    while (he = hv_iternext(stash)) {
        SV *key = HeSVKEY_force(he);
        char *key_str = SvPV_nolen(key);
        Local<String> name = String::New(key_str);

        if (prototype->Has(name))
            continue;

        PerlFunctionData* pfd
            = name->Equals(string_to_js) // we want to_js() to be called as a package function
            ? new PerlFunctionData(this, (SV*)GvCV(gv_fetchmethod(stash, key_str)))
            : new PerlMethodData(this, key_str);

        prototype->Set(name, pfd->object);
    }
}
Exemplo n.º 8
0
  static Persistent<Object> getPlugin(shared_ptr<PluginContext> script)
  {
    Context::Scope context_scope(script->getContext());
    HandleScope handleScope;
    Handle<Object> global = script->getContext()->Global();

    if (global->Has(String::New("plugin")) == false)
    {
      throw IllegalArgumentException("Expected the script to have exports.");
    }

    Handle<Value> pluginValue = global->Get(String::New("plugin"));
    Persistent<Object> plugin = Persistent<Object>::New(Handle<Object>::Cast(pluginValue));
    if (plugin.IsEmpty() || plugin->IsObject() == false)
    {
      throw IllegalArgumentException("Expected plugin to be a valid object.");
    }

    return plugin;
  }
Exemplo n.º 9
0
  static double getNumber(Handle<Object> obj, QString key, double minValue, double defaultValue)
  {
    double result = defaultValue;
    Handle<String> cdtKey = String::New(key.toUtf8());
    if (obj->Has(cdtKey))
    {
      Local<Value> v = obj->Get(cdtKey);
      if (v->IsNumber() == false)
      {
        throw IllegalArgumentException("Expected " + key + " to be a number.");
      }
      result = v->NumberValue();

      if (result < minValue)
      {
        throw IllegalArgumentException(QString("Expected %1 to be greater than %2.")
                                       .arg(key).arg(minValue));
      }
    }
    return result;
  }
Exemplo n.º 10
0
std::string ScriptEnvironment::GetInfo()
{
    std::string info;
    info += std::string("V8 Javascript Engine ") + V8::GetVersion() + std::string("\n");

    With(
            [&](const Handle<Context>& context)
            {
                Handle<String> key = String::New("CoffeeScript");
                Handle<Object> compiler = context->Global()->GetHiddenValue(key)->ToObject();
                if (compiler->Has(String::New("VERSION"))) {
                    info += "CoffeeScript ";
                    info += *String::AsciiValue(compiler->Get(String::New("VERSION"))->ToString());
                    info += "\n";
                }
            });

    info += "Sugar Library v1.2.5";

    return info;
}
Exemplo n.º 11
0
int Interface::DictImport(JNIEnv *jniEnv, Handle<Object> val, jobject jVal) {
  jobjectArray args = (jobjectArray)jniEnv->CallStaticObjectMethod(jDictStub, jDictGetArgs);
  jniEnv->MonitorEnter(args);
  int result = OK;
  for(int i = 0; i < attributes->getLength(); i++) {
    jobject jMember;
    Handle<String> attrName = attributes->addr(i)->name;
    Local<Value> member = val->Has(attrName) ? val->Get(attrName) : Local<Value>();
    result = conv->ToJavaObject(jniEnv, member, attributes->addr(i)->type, &jMember);
    if(result != OK) break;
    jniEnv->SetObjectArrayElement(args, i, jMember);
  }
  if(result == OK) {
    jniEnv->CallStaticVoidMethod(jDictStub, jDictImport, jVal, args);
  }
  jniEnv->MonitorExit(args);
  if(result == OK && parent != 0) {
    result = parent->DictImport(jniEnv, val, jVal);
  }
  return result;
}
Exemplo n.º 12
0
  static Local<Object> getPlugin(boost::shared_ptr<PluginContext> script)
  {
    Isolate* current = v8::Isolate::GetCurrent();
    EscapableHandleScope handleScope(current);
    Context::Scope context_scope(script->getContext(current));
    Handle<Object> global = script->getContext(current)->Global();

    if (global->Has(String::NewFromUtf8(current, "plugin")) == false)
    {
      throw IllegalArgumentException("Expected the script to have exports.");
    }

    Handle<Value> pluginValue = global->Get(String::NewFromUtf8(current, "plugin"));
    Handle<Object> plugin(Handle<Object>::Cast(pluginValue));
    if (plugin.IsEmpty() || plugin->IsObject() == false)
    {
      throw IllegalArgumentException("Expected plugin to be a valid object.");
    }

    return handleScope.Escape(plugin);
  }
Exemplo n.º 13
0
  static double getNumber(Handle<Object> obj, QString key, double minValue, double defaultValue)
  {
    Isolate* current = v8::Isolate::GetCurrent();
    HandleScope handleScope(current);
    double result = defaultValue;
    Handle<String> cdtKey = String::NewFromUtf8(current, key.toUtf8());
    if (obj->Has(cdtKey))
    {
      Local<Value> v = obj->Get(cdtKey);
      if (v->IsNumber() == false || ::qIsNaN(v->NumberValue()))
      {
        throw IllegalArgumentException("Expected " + key + " to be a number.");
      }
      result = v->NumberValue();

      if (result < minValue)
      {
        throw IllegalArgumentException(QString("Expected %1 to be greater than %2.")
                                       .arg(key).arg(minValue));
      }
    }
    return result;
  }
Exemplo n.º 14
0
 V8FunctionData(V8Context* context_, Handle<Object> object_, SV* sv_)
     : V8ObjectData(context_, object_, sv_)
     , returns_list(object_->Has(String::New("__perlReturnsList")))
 { }
Exemplo n.º 15
0
int main(int argc, char* argv[]) {
	SDL_Init(SDL_INIT_EVERYTHING);

	V8::Initialize();
	isolate = Isolate::GetCurrent();
	HandleScope handle_scope(isolate);
	
	Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);

	Local<Object> global = context->Global();
	
	Local<Object> sphere = Object::New();
	
	global->Set(String::New("sphere"), sphere);
	
	API::fs::Init(sphere);
	API::engine::Init(sphere);
	API::graphics::Init(sphere);
	API::events::Init(sphere);
	
	Local<Object> engine = sphere->Get(String::New("engine"))->ToObject();
	
	engine->Set(String::New("argc"), Integer::New(argc));
	Local<Array> js_argv = Array::New(argc);
	
	for (int i = 0; i < argc; i++) {
		js_argv->Set(Number::New(i), String::New(argv[i]));
	}

	engine->Set(String::New("argv"), js_argv);
	
	const char* gameScript = Files::readTextFile("system/sphere.js");
	
	if (gameScript == NULL) {
		debug("Error loading bootstrap script.\n");
		exit(1);
	}
	
	TryCatch trycatch;
	Local<Script> compiled = Script::Compile(String::New(gameScript), String::New("system/sphere.js"));
	
	if (compiled.IsEmpty()) {
		Handle<Value> exception = trycatch.Exception();
		String::Utf8Value exception_str(exception);
		printf("Exception: %s\n", *exception_str);
		exit(1);
	}
	
	Handle<Value> value = compiled->Run();
	
	if (value.IsEmpty()) {
		Handle<Object> exception = trycatch.Exception()->ToObject();
		Handle<String> str;
		if (exception->Has(String::New("stack"))) {
			str = exception->Get(String::New("stack"))->ToString();
		}
		else {
			str = exception->ToString();
		}
		String::Utf8Value exception_str(str);
		printf("Exception: %s\n", *exception_str);
		exit(1);
	}
	
	return 0;
}
Exemplo n.º 16
0
METHOD_RETURN_TYPE CreateWriter(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    Handle<Value> instance = PDFWriterDriver::GetNewInstance(args);
    
    PDFWriterDriver* driver = ObjectWrap::Unwrap<PDFWriterDriver>(instance->ToObject());

	if (args.Length() < 1 || args.Length() > 2) {
		THROW_EXCEPTION("Wrong number of arguments, Provide one argument stating the location of the output file, and an optional options object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
	if (!args[0]->IsString() && !args[0]->IsObject()) {
		THROW_EXCEPTION("Wrong arguments, please provide a path to a file as the first argument or a stream object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
    EPDFVersion pdfVersion = ePDFVersion13;
    bool compressStreams = true;
    LogConfiguration logConfig = LogConfiguration::DefaultLogConfiguration;
    
    if(args.Length() == 2 && args[1]->IsObject())
    {
        Handle<Object> anObject = args[1]->ToObject();
        if(anObject->Has(NEW_STRING("version")) && anObject->Get(NEW_STRING("version"))->IsNumber())
        {
            long pdfVersionValue = anObject->Get(NEW_STRING("version"))->ToNumber()->Int32Value();
            
            if(pdfVersionValue < ePDFVersion10 || ePDFVersionMax < pdfVersionValue)
            {
                THROW_EXCEPTION("Wrong argument for PDF version, please provide a valid PDF version");
                SET_FUNCTION_RETURN_VALUE(UNDEFINED);
            }
            pdfVersion = (EPDFVersion)pdfVersionValue;
        }
            
        if(anObject->Has(NEW_STRING("compress")) && anObject->Get(NEW_STRING("compress"))->IsBoolean())
            compressStreams = anObject->Get(NEW_STRING("compress"))->ToBoolean()->Value();

        if(anObject->Has(NEW_STRING("log")) && anObject->Get(NEW_STRING("log"))->IsString())
        {
            logConfig.ShouldLog = true;
            logConfig.LogFileLocation = *String::Utf8Value(anObject->Get(NEW_STRING("log"))->ToString());
        }

    }
    
    EStatusCode status;
    
    if(args[0]->IsObject())
    {
        status = driver->StartPDF(args[0]->ToObject(), pdfVersion,logConfig,PDFCreationSettings(compressStreams,true));
    }
    else
    {
        status = driver->StartPDF(std::string(*String::Utf8Value(args[0]->ToString())), pdfVersion,logConfig,PDFCreationSettings(compressStreams,true));
    }
    
    if(status != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("Unable to create PDF file, make sure that output file target is available");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    SET_FUNCTION_RETURN_VALUE(instance);

}
Exemplo n.º 17
0
METHOD_RETURN_TYPE CreateWriterToModify(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    Handle<Value> instance = PDFWriterDriver::GetNewInstance(args);
    
    PDFWriterDriver* driver = ObjectWrap::Unwrap<PDFWriterDriver>(instance->ToObject());
    
    if(args.Length() < 1 ||
       (!args[0]->IsString() && !args[0]->IsObject()) ||
       (args[0]->IsString() && args.Length() > 2) ||
       (args[0]->IsObject() && (!args[1]->IsObject() || args.Length() > 3)))
    {
		THROW_EXCEPTION("Wrong arguments, please path a path to modified file, or a pair of stream - first for the source, and second for destination. in addition you can optionally add an options object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
    
    EPDFVersion pdfVersion = ePDFVersion10;
    bool compressStreams = true;
    std::string alternativePath;
    Handle<Value> alternativeStream;
    LogConfiguration logConfig = LogConfiguration::DefaultLogConfiguration;
    
    int optionsObjectIndex = args[0]->IsString() ? 1:2;
    
    if(args.Length() == (optionsObjectIndex+1) && args[optionsObjectIndex]->IsObject())
    {
        Handle<Object> anObject = args[optionsObjectIndex]->ToObject();
        if(anObject->Has(NEW_STRING("version")) && anObject->Get(NEW_STRING("version"))->IsString())
        {
            long pdfVersionValue = anObject->Get(NEW_STRING("version"))->ToNumber()->Int32Value();
            
            if(pdfVersionValue < ePDFVersion10 || ePDFVersionMax < pdfVersionValue)
            {
                THROW_EXCEPTION("Wrong argument for PDF version, please provide a valid PDF version");
                SET_FUNCTION_RETURN_VALUE(UNDEFINED);
            }
            pdfVersion = (EPDFVersion)pdfVersionValue;
        }
        
        if(anObject->Has(NEW_STRING("compress")) && anObject->Get(NEW_STRING("compress"))->IsBoolean())
            compressStreams = anObject->Get(NEW_STRING("compress"))->ToBoolean()->Value();
        
        if(anObject->Has(NEW_STRING("modifiedFilePath")) && anObject->Get(NEW_STRING("modifiedFilePath"))->IsString())
            alternativePath = *String::Utf8Value(anObject->Get(NEW_STRING("modifiedFilePath"))->ToString());

        if(anObject->Has(NEW_STRING("log")) && anObject->Get(NEW_STRING("log"))->IsString())
        {
            logConfig.ShouldLog = true;
            logConfig.LogFileLocation = *String::Utf8Value(anObject->Get(NEW_STRING("log"))->ToString());
        }
    }
    
    EStatusCode status;
    
    if(args[0]->IsObject())
    {
        status = driver->ModifyPDF(args[0]->ToObject(),
                                   args[1]->ToObject(),
                                   pdfVersion,
                                   logConfig,
                                   PDFCreationSettings(compressStreams,true));
    }
    else
    {
        status = driver->ModifyPDF(*String::Utf8Value(args[0]->ToString()),
                               pdfVersion,alternativePath,logConfig,
                               PDFCreationSettings(compressStreams,true));
    }
    
    if(status != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("Unable to modify PDF file, make sure that output file target is available and that it is not protected");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    SET_FUNCTION_RETURN_VALUE(instance);
}
Exemplo n.º 18
0
METHOD_RETURN_TYPE CreateWriterToContinue(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    Handle<Value> instance = PDFWriterDriver::GetNewInstance(args);
    
    PDFWriterDriver* driver = ObjectWrap::Unwrap<PDFWriterDriver>(instance->ToObject());
    
	if ((args.Length() != 2  && args.Length() !=3)||
            (!args[0]->IsString() && !args[0]->IsObject()) ||
            !args[1]->IsString() ||
            ((args.Length() == 3) && !args[2]->IsObject())) {
		THROW_EXCEPTION("Wrong arguments, provide 2 strings - path to file to continue, and path to state file (provided to the previous shutdown call. You may also add an options object");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
	}
    
    std::string alternativePath;
    Handle<Object> alternativeStream;
    LogConfiguration logConfig = LogConfiguration::DefaultLogConfiguration;
   
    if(args.Length() == 2 && args[1]->IsObject())
    {
        Handle<Object> anObject = args[1]->ToObject();
        
        if(anObject->Has(NEW_STRING("modifiedFilePath")) && anObject->Get(NEW_STRING("modifiedFilePath"))->IsString())
            alternativePath = *String::Utf8Value(anObject->Get(NEW_STRING("modifiedFilePath"))->ToString());

        if(anObject->Has(NEW_STRING("modifiedStream")) && anObject->Get(NEW_STRING("modifiedStream"))->IsObject())
            alternativeStream = anObject->Get(NEW_STRING("modifiedStream"))->ToObject();
        
        
        if(anObject->Has(NEW_STRING("log")))
        {
            Handle<Value> value = anObject->Get(NEW_STRING("log"));
            if(value->IsString())
            {
                logConfig.ShouldLog = true;
                logConfig.LogFileLocation = *String::Utf8Value(anObject->Get(NEW_STRING("log"))->ToString());
                logConfig.LogStream = NULL;
            }
            else if(value->IsObject())
            {
                logConfig.ShouldLog = true;
                logConfig.LogFileLocation = "";
                ObjectByteWriter proxy(value->ToObject());
                logConfig.LogStream = &proxy;
            }
        }
    }
    
    EStatusCode status;
    
    if(args[0]->IsObject())
    {
        status = driver->ContinuePDF(args[0]->ToObject(),
                                     *String::Utf8Value(args[1]->ToString()),
                                     alternativeStream,
                                     logConfig);
    }
    else
    {
        status = driver->ContinuePDF(*String::Utf8Value(args[0]->ToString()),
                                             *String::Utf8Value(args[1]->ToString()),
                                             alternativePath,
                                             logConfig);
    }
    
    if(status != PDFHummus::eSuccess)
    {
		THROW_EXCEPTION("Unable to continue PDF file, make sure that output file target is available and state file exists");
		SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    SET_FUNCTION_RETURN_VALUE(instance);
}