当前位置: 首页>>代码示例>>C++>>正文


C++ Persistent::Dispose方法代码示例

本文整理汇总了C++中Persistent::Dispose方法的典型用法代码示例。如果您正苦于以下问题:C++ Persistent::Dispose方法的具体用法?C++ Persistent::Dispose怎么用?C++ Persistent::Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Persistent的用法示例。


在下文中一共展示了Persistent::Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: context_scope

void
test_AsciiValue_length()
{
  HandleScope handle_scope;
  Persistent<Context> context = Context::New();
  Context::Scope context_scope(context);

  char TEST_STRING[] = "toString";
  int TEST_LENGTH = strlen(TEST_STRING);
  Handle<String> str = String::New(TEST_STRING);
  do_check_eq(str->Length(), TEST_LENGTH);
  String::AsciiValue k(str);
  do_check_eq(k.length(), TEST_LENGTH);
  context.Dispose();
}
开发者ID:bjonreyes,项目名称:spidernode,代码行数:15,代码来源:test_String.cpp

示例2: DisposeOpenCLObject

  void DisposeOpenCLObject (Persistent<Value> value, void* release) {
    if (release && value->IsObject()) {
      Local<Object> object = value->ToObject();
      if (object->InternalFieldCount()) {
        void *ptr = object->GetPointerFromInternalField(0);

        int32_t (CALL *clRelease) (void* smth);
        *(void**) &clRelease = release;

        clRelease(ptr); // Returned value is omitted. Check when debugging.
      }
    }

    value.Dispose();
    value.Clear();
  }
开发者ID:brainshave,项目名称:v8cl,代码行数:16,代码来源:callbacks.cpp

示例3: initJsEngine

// Load up the JS engine
void initJsEngine(){
    char path[1024];
    uint32_t size = sizeof(path);
    if (_NSGetExecutablePath(path, &size) != 0)
       printf("buffer too small; need size %u\n", size);
    
    string script_path;
    char *pch, *next_pch;
    pch = strtok(path, "/");
    next_pch = strtok(NULL, "/");
    //Rebuild the path, ommitting the last part (the exe name)
    while (next_pch != NULL) {
        script_path.append( "/" );
        script_path.append( pch );
        pch = next_pch;
        next_pch = strtok(NULL, "/");
    }
    script_path.append("/script.js");
    ifstream infile;
    
    infile.open (script_path.c_str(), ifstream::in);
    string file = "";
    while (infile.good()){
        file += (char) infile.get();
    }
    //Get rid of the of character
    file[file.length() - 1] = ' ';
    setJsFile( file.c_str() );
    infile.close();

    // Lock this v8 instance to this thread?
    Locker locker;
    HandleScope handle_scope;
    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);
    

    context->Global()->Set(String::New("System"), getSystemTemplate()->NewInstance() ); 
    context->Global()->Set(String::New("Player"), getPlayerTemplate()->NewInstance() );
    context->Global()->Set(String::New("Games"),  getGamesTemplate()->NewInstance() );
    
    Handle<String> source = String::New(js_file);
    Handle<Script> script = Script::Compile(source);
    Handle<Value> result = script->Run();
    context.Dispose();
}
开发者ID:Velkitor,项目名称:C---Mastermind-played-by-JavaScript,代码行数:47,代码来源:javascript_main.cpp

示例4: RemoveFromComponentMap

   bool ScriptSystem::RemoveFromComponentMap(dtEntity::ComponentType ct, dtEntity::EntityId eid)
   {
      ComponentMap::iterator it = mComponentMap.find(std::make_pair(ct, eid));
      if(it == mComponentMap.end())
      {
         return false;
      }
      HandleScope scope;
      Persistent<Object> obj = it->second;
      assert(!obj.IsEmpty() && obj->IsObject());
      // invalidate component wrapper
      obj->SetInternalField(0, External::New(0));
      obj.Dispose();
      mComponentMap.erase(it);
      V8::AdjustAmountOfExternalAllocatedMemory(-(int)sizeof(dtEntity::Component));
      return true;

   }
开发者ID:mathieu,项目名称:dtEntity,代码行数:18,代码来源:scriptcomponent.cpp

示例5: context_scope

void
test_obj_getprop()
{
  HandleScope handle_scope;

  Persistent<Context> context = Context::New();

  Context::Scope context_scope(context);

  Handle<Object> obj = Object::New();

  Handle<Value> k = String::New("toString");
  Handle<Value> v = obj->Get(k);

  do_check_true(v->IsFunction());

  context.Dispose();
}
开发者ID:mmmulani,项目名称:v8monkey,代码行数:18,代码来源:test_objprop.cpp

示例6: main

int main (int argc, char const *argv[])
{
	HandleScope handle_scope;
	
	Handle<ObjectTemplate> global = ObjectTemplate::New();
	
	global->Set(String::New("load"), FunctionTemplate::New(js_load));
	Persistent<Context> context = Context::New(NULL, global);
	Context::Scope context_scope(context);
	Handle<Object> global_obj(context->Global());
	IO::initialize(global_obj);
	Process::initialize(global_obj);
	
	Handle<Value> result = LoadScript(argv[1]);
	
	context.Dispose();
	
	return 0;
}
开发者ID:simonask,项目名称:js,代码行数:19,代码来源:main.cpp

示例7: keyStr

Handle<Value> HashTable::Remove(const Arguments& args) {
  HandleScope scope;

  HashTable *obj = ObjectWrap::Unwrap<HashTable>(args.This());

  Local<Value> key = Local<Value>(args[0]);
  String::AsciiValue keyStr(key);

  auto itr = obj->map.find(std::string(*keyStr));

  if(itr == obj->map.end()) {
    return scope.Close(Local<Value>()); //do nothing and return undefined
  } 

  Persistent<Value> value = itr->second;
  value.Dispose();

  obj->map.erase(itr);

  return scope.Close(Local<Value>());
}
开发者ID:IbpTeam,项目名称:node-hashtable,代码行数:21,代码来源:hashtable.cpp

示例8: js_eval

char* js_eval(UDF_INIT *initid, UDF_ARGS* args, char *result_buf, unsigned long *res_length, char *null_value, char *error) {

    HandleScope handle_scope;

    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);

    //fprintf(stderr, "[mylog] input: %s\n", (char*)(args->args[0]));

    Handle<String> source = String::New((char*)(args->args[0]));
    Handle<Script> script = Script::Compile(source);

    TryCatch trycatch;
    Handle<Value> result = script->Run();

    if ( result.IsEmpty() ) {
        Handle<Value> exception = trycatch.Exception();
        String::AsciiValue exception_str(exception);

        //fprintf(stderr, "[mylog] exception: %s\n", *exception_str);

        strcpy(result_buf, *exception_str);
        *res_length = strlen(*exception_str);
    }
    else {
        String::AsciiValue ascii(result);

        //fprintf(stderr, "[mylog] output: %s\n", *ascii);

        strcpy(result_buf, *ascii);
        *res_length = strlen(*ascii);
    }

    context.Dispose();

    return result_buf;
}
开发者ID:zentooo,项目名称:mysqludf-jseval,代码行数:37,代码来源:js_eval.cpp

示例9: CompletionGenerator

char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
  static unsigned current_index;
  static Persistent<Array> current_completions;
  if (state == 0) {
    i::SmartPointer<char> full_text(i::StrNDup(rl_line_buffer, rl_point));
    HandleScope scope;
    Handle<Array> completions =
      Shell::GetCompletions(String::New(text), String::New(*full_text));
    current_completions = Persistent<Array>::New(completions);
    current_index = 0;
  }
  if (current_index < current_completions->Length()) {
    HandleScope scope;
    Handle<Integer> index = Integer::New(current_index);
    Handle<Value> str_obj = current_completions->Get(index);
    current_index++;
    String::Utf8Value str(str_obj);
    return strdup(*str);
  } else {
    current_completions.Dispose();
    current_completions.Clear();
    return NULL;
  }
}
开发者ID:BlitzMaxModules,项目名称:axe.mod,代码行数:24,代码来源:d8-readline.cpp

示例10: Java_me_sarim_myfirstapp_MainActivity_killjs

void Java_me_sarim_myfirstapp_MainActivity_killjs( JNIEnv* env,jobject thiz){
	
	Context::Scope context_scope(context);
	context.Dispose();
	
}
开发者ID:sarim,项目名称:avrov8,代码行数:6,代码来源:avrov8.cpp

示例11: Java_com_omicronlab_avrokeyboard_PhoneticIM_killjs

void Java_com_omicronlab_avrokeyboard_PhoneticIM_killjs( JNIEnv* env,jobject thiz){
	
	Context::Scope context_scope(context);
	context.Dispose();
	
}
开发者ID:azizur77,项目名称:Avrodroid,代码行数:6,代码来源:avrov8.cpp

示例12:

/* static */
void V8Runtime::collectWeakRef(Persistent<Value> ref, void *parameter)
{
	jobject v8Object = (jobject) parameter;
	ref.Dispose();
	JNIScope::getEnv()->DeleteGlobalRef(v8Object);
}
开发者ID:EnochManohar,项目名称:titanium_mobile,代码行数:7,代码来源:V8Runtime.cpp

示例13: jniScope

JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeDispose(JNIEnv *env, jobject runtime)
{
	JNIScope jniScope(env);

	// We use a new scope here so any new handles we create
	// while disposing are cleaned up before our global context
	// is disposed below.
	{
		HandleScope scope;

		// Any module that has been require()'d or opened via Window URL
		// will be cleaned up here. We setup the initial "moduleContexts"
		// Array and expose it on kroll above in nativeInit, and
		// module.js will insert module contexts into this array in
		// Module.prototype._runScript
		uint32_t length = V8Runtime::moduleContexts->Length();
		for (uint32_t i = 0; i < length; ++i) {
			Handle<Value> moduleContext = V8Runtime::moduleContexts->Get(i);

			// WrappedContext is simply a C++ wrapper for the V8 Context object,
			// and is used to expose the Context to javascript. See ScriptsModule for
			// implementation details
			WrappedContext *wrappedContext = NativeObject::Unwrap<WrappedContext>(moduleContext->ToObject());

			// Detach each context's global object, and dispose the context
			wrappedContext->GetV8Context()->DetachGlobal();
			wrappedContext->GetV8Context().Dispose();
		}

		// KrollBindings
		KrollBindings::dispose();
		EventEmitter::dispose();

		V8Runtime::moduleContexts.Dispose();
		V8Runtime::moduleContexts = Persistent<Array>();

		V8Runtime::globalContext->DetachGlobal();

	}

	// Dispose of each class' static cache / resources

	V8Util::dispose();
	ProxyFactory::dispose();

	moduleObject.Dispose();
	moduleObject = Persistent<Object>();

	runModuleFunction.Dispose();
	runModuleFunction = Persistent<Function>();

	V8Runtime::krollGlobalObject.Dispose();

	V8Runtime::globalContext->Exit();
	V8Runtime::globalContext.Dispose();

	// Removes the retained global reference to the V8Runtime 
	env->DeleteGlobalRef(V8Runtime::javaInstance);

	V8Runtime::javaInstance = NULL;
}
开发者ID:EnochManohar,项目名称:titanium_mobile,代码行数:61,代码来源:V8Runtime.cpp

示例14: ThrowException

Handle<Value> WrappedScript::EvalMachine(const Arguments& args)
{
	HandleScope scope;

	if (input_flag == compileCode && args.Length() < 1) {
		return ThrowException(Exception::TypeError(String::New("needs at least 'code' argument.")));
	}

	const int sandbox_index = input_flag == compileCode ? 1 : 0;
	if (context_flag == userContext && args.Length() < (sandbox_index + 1)) {
		return ThrowException(Exception::TypeError(String::New("needs a 'context' argument.")));
	}

	Local<String> code;
	if (input_flag == compileCode) code = args[0]->ToString();

	Local<Object> sandbox;
	if (context_flag == newContext) {
		sandbox = args[sandbox_index]->IsObject() ? args[sandbox_index]->ToObject() : Object::New();
	} else if (context_flag == userContext) {
		sandbox = args[sandbox_index]->ToObject();
	}

	int filename_offset = 1;
	if (context_flag == thisContext) {
		filename_offset = 0;
	}

	const int filename_index = sandbox_index + filename_offset;
	Local<String> filename =
		args.Length() > filename_index ? args[filename_index]->ToString() : String::New("evalmachine.<anonymous>");

	const int display_error_index = args.Length() - 1;
	bool display_error = false;
	if (args.Length() > display_error_index && args[display_error_index]->IsBoolean()
		&& args[display_error_index]->BooleanValue() == true) {
		display_error = true;
	}

	Persistent<Context> context;

	Local<Array> keys;
	unsigned int i;
	WrappedContext *nContext = NULL;
	Local<Object> contextArg;

	if (context_flag == newContext) {
		// Create the new context
		context = Context::New();

	} else if (context_flag == userContext) {
		// Use the passed in context
		contextArg = args[sandbox_index]->ToObject();
		nContext = WrappedContext::Unwrap(contextArg);
		context = nContext->GetV8Context();
	}

	// New and user context share code. DRY it up.
	if (context_flag == userContext || context_flag == newContext) {
		// Enter the context
		context->Enter();
	}

	Handle<Value> result;
	Handle<Script> script;

	if (input_flag == compileCode) {
		// well, here WrappedScript::New would suffice in all cases, but maybe
		// Compile has a little better performance where possible
		script = output_flag == returnResult ? Script::Compile(code, filename) : Script::New(code, filename);
		if (script.IsEmpty()) {
			// Hack because I can't get a proper stacktrace on SyntaxError
			return Undefined();
		}
	} else {
		WrappedScript *n_script = NativeObject::Unwrap<WrappedScript>(args.Holder());
		if (!n_script) {
			return ThrowException(Exception::Error(String::New("Must be called as a method of Script.")));
		} else if (n_script->script_.IsEmpty()) {
			return ThrowException(Exception::Error(String::New("'this' must be a result of previous "
				"new Script(code) call.")));
		}

		script = n_script->script_;
	}

	if (output_flag == returnResult) {
		result = script->Run();
		if (result.IsEmpty()) {
			if (context_flag == newContext) {
				context->DetachGlobal();
				context->Exit();
				context.Dispose();
			}
			return Undefined();
		}
	} else {
		WrappedScript *n_script = NativeObject::Unwrap<WrappedScript>(args.Holder());
		if (!n_script) {
			return ThrowException(Exception::Error(String::New("Must be called as a method of Script.")));
//.........这里部分代码省略.........
开发者ID:0anasm,项目名称:titanium_mobile,代码行数:101,代码来源:ScriptsModule.cpp

示例15: ThrowException


//.........这里部分代码省略.........
	// New and user context share code. DRY it up.
	if (context_flag == userContext || context_flag == newContext) {
		// Enter the context
		context->Enter();

		// Call the initCallback, if it exists
		if (nContext) {
			Persistent<Function> initCallback = nContext->GetInitCallback();

			if (!initCallback.IsEmpty()) {
				Handle<Value> callbackArgs[] = { contextArg, context->Global() };
				initCallback->Call(contextArg, 2, callbackArgs);
			}
		}

		// Copy everything from the passed in sandbox (either the persistent
		// context for runInContext(), or the sandbox arg to runInNewContext()).
		keys = sandbox->GetPropertyNames();

		for (i = 0; i < keys->Length(); i++) {
			Handle<String> key = keys->Get(Integer::New(i))->ToString();
			Handle<Value> value = sandbox->Get(key);
			if (value == sandbox) {
				value = context->Global();
			}
			context->Global()->Set(key, value);
		}
	}

	Handle<Value> result;
	Handle<Script> script;

	if (input_flag == compileCode) {
		// well, here WrappedScript::New would suffice in all cases, but maybe
		// Compile has a little better performance where possible
		script = output_flag == returnResult ? Script::Compile(code, filename) : Script::New(code, filename);
		if (script.IsEmpty()) {
			// Hack because I can't get a proper stacktrace on SyntaxError
			return Undefined();
		}
	} else {
		WrappedScript *n_script = NativeObject::Unwrap<WrappedScript>(args.Holder());
		if (!n_script) {
			return ThrowException(Exception::Error(String::New("Must be called as a method of Script.")));
		} else if (n_script->script_.IsEmpty()) {
			return ThrowException(Exception::Error(String::New("'this' must be a result of previous "
				"new Script(code) call.")));
		}

		script = n_script->script_;
	}

	if (output_flag == returnResult) {
		result = script->Run();
		if (result.IsEmpty()) {
			if (context_flag == newContext) {
				context->DetachGlobal();
				context->Exit();
				context.Dispose();
			}
			return Undefined();
		}
	} else {
		WrappedScript *n_script = NativeObject::Unwrap<WrappedScript>(args.Holder());
		if (!n_script) {
			return ThrowException(Exception::Error(String::New("Must be called as a method of Script.")));
		}
		n_script->script_ = Persistent<Script>::New(script);
		result = args.This();
	}

	if (context_flag == userContext || context_flag == newContext) {
		// success! copy changes back onto the sandbox object.
		keys = context->Global()->GetPropertyNames();
		for (i = 0; i < keys->Length(); i++) {
			Handle<String> key = keys->Get(Integer::New(i))->ToString();
			Handle<Value> value = context->Global()->Get(key);
			if (value == context->Global()) {
				value = sandbox;
			}
			sandbox->Set(key, value);
		}
	}

	if (context_flag == newContext) {
		// Clean up, clean up, everybody everywhere!
		context->DetachGlobal();
		context->Exit();
		context.Dispose();
	} else if (context_flag == userContext) {
		// Exit the passed in context.
		context->Exit();
	}

	if (result->IsObject()) {
		Local<Context> creation = result->ToObject()->CreationContext();
	}

	return result == args.This() ? result : scope.Close(result);
}
开发者ID:QGao,项目名称:titanium_mobile,代码行数:101,代码来源:ScriptsModule.cpp


注:本文中的Persistent::Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。