Exemplo n.º 1
0
static void init(Handle<Object> target) {
  target->Set(String::NewSymbol("popen"),
    FunctionTemplate::New(NodePopen)->GetFunction());
  target->Set(String::NewSymbol("popen2"),
    FunctionTemplate::New(NodePopen2)->GetFunction());
}
Exemplo n.º 2
0
static Handle<Value> NodePopen2(const Arguments& args) {
  HandleScope scope;
  
  // Expect a callback function for stdout
  Handle<String> Command = Handle<String  >::Cast(args[0]);
  Handle<Array> ArgArray = Handle<Array   >::Cast(args[1]);
  
  // Create Pipes for STDIN, STDOUT, and STDERR //
  
  int PIPE_READ  = 0;
  int PIPE_WRITE = 1;
  
  int pipe_stdin [2]; // [read,write]
  int pipe_stdout[2];
  int pipe_stderr[2];
  
  pipe (pipe_stdin);
  pipe (pipe_stdout);
  pipe (pipe_stderr);
  
  pid_t pid;
  pid = fork();
  
  Handle<Object> ob = Object::New();
  
  if(pid == (pid_t) 0)
  {
    // Child //
    
    char* command = getAscii(Command);  
    
    int arrayLen = ArgArray->Length();
    char* pargs[arrayLen + 2];
    
    // Create Argument Array from JavaScript Array
    pargs[0] = command;
    for(int i=0; i < arrayLen; i++)
    {
      pargs[i+1] = getAscii(Handle<String>::Cast( ArgArray->Get(i) ));
    }
    pargs[arrayLen+1] = '\0';
    
    // Close Unused Pipe Ends for Child
    close( pipe_stdin [PIPE_WRITE] );
    close( pipe_stdout[PIPE_READ]  );
    close( pipe_stderr[PIPE_READ]  );
    
    // Switch Standard File Descriptors to IPC Pipes
    dup2( pipe_stdin [PIPE_READ ], STDIN_FILENO  );
    dup2( pipe_stdout[PIPE_WRITE], STDOUT_FILENO );
    dup2( pipe_stderr[PIPE_WRITE], STDERR_FILENO );
    
    
    int code = execvp(command, pargs);
    
    _exit(code);
    
  }
  else
  {
    // Parent
    
    // Close Unused Ends for Parent
    close( pipe_stdin [PIPE_READ]  );
    close( pipe_stdout[PIPE_WRITE] );
    close( pipe_stderr[PIPE_WRITE] );
    
    std::string stdout;
    std::string stderr;
    
    char buffer;
    
    while( read(pipe_stdout[PIPE_READ], &buffer, 1 ) > 0 )
    {
      stdout.append( 1, buffer );
    }
    
    while( read(pipe_stderr[PIPE_READ], &buffer, 1 ) > 0 )
    {
      stderr.append( 1, buffer );
    }
    
    int status;
    waitpid(pid, &status, 0);
    
    ob->Set( String::NewSymbol("code"),   Integer::New(status) );
    ob->Set( String::NewSymbol("stdout"), String::New(stdout.c_str()) );
    ob->Set( String::NewSymbol("stderr"), String::New(stderr.c_str()) );
    
  }
  
  return scope.Close(ob);
}
Exemplo n.º 3
0
 V8FunctionData(V8Context* context_, Handle<Object> object_, SV* sv_)
     : V8ObjectData(context_, object_, sv_)
     , returns_list(object_->Has(String::New("__perlReturnsList")))
 { }
Exemplo n.º 4
0
void ConstantPoolCacheEntry::set_method_handle_common(const constantPoolHandle& cpool,
                                                      Bytecodes::Code invoke_code,
                                                      const CallInfo &call_info) {
  // NOTE: This CPCE can be the subject of data races.
  // There are three words to update: flags, refs[f2], f1 (in that order).
  // Writers must store all other values before f1.
  // Readers must test f1 first for non-null before reading other fields.
  // Competing writers must acquire exclusive access via a lock.
  // A losing writer waits on the lock until the winner writes f1 and leaves
  // the lock, so that when the losing writer returns, he can use the linked
  // cache entry.

  objArrayHandle resolved_references = cpool->resolved_references();
  // Use the resolved_references() lock for this cpCache entry.
  // resolved_references are created for all classes with Invokedynamic, MethodHandle
  // or MethodType constant pool cache entries.
  assert(resolved_references() != NULL,
         "a resolved_references array should have been created for this class");
  ObjectLocker ol(resolved_references, Thread::current());
  if (!is_f1_null()) {
    return;
  }

  const methodHandle adapter = call_info.resolved_method();
  const Handle appendix      = call_info.resolved_appendix();
  const Handle method_type   = call_info.resolved_method_type();
  const bool has_appendix    = appendix.not_null();
  const bool has_method_type = method_type.not_null();

  // Write the flags.
  set_method_flags(as_TosState(adapter->result_type()),
                   ((has_appendix    ? 1 : 0) << has_appendix_shift   ) |
                   ((has_method_type ? 1 : 0) << has_method_type_shift) |
                   (                   1      << is_final_shift       ),
                   adapter->size_of_parameters());

  if (TraceInvokeDynamic) {
    ttyLocker ttyl;
    tty->print_cr("set_method_handle bc=%d appendix=" PTR_FORMAT "%s method_type=" PTR_FORMAT "%s method=" PTR_FORMAT " ",
                  invoke_code,
                  p2i(appendix()),    (has_appendix    ? "" : " (unused)"),
                  p2i(method_type()), (has_method_type ? "" : " (unused)"),
                  p2i(adapter()));
    adapter->print();
    if (has_appendix)  appendix()->print();
  }

  // Method handle invokes and invokedynamic sites use both cp cache words.
  // refs[f2], if not null, contains a value passed as a trailing argument to the adapter.
  // In the general case, this could be the call site's MethodType,
  // for use with java.lang.Invokers.checkExactType, or else a CallSite object.
  // f1 contains the adapter method which manages the actual call.
  // In the general case, this is a compiled LambdaForm.
  // (The Java code is free to optimize these calls by binding other
  // sorts of methods and appendices to call sites.)
  // JVM-level linking is via f1, as if for invokespecial, and signatures are erased.
  // The appendix argument (if any) is added to the signature, and is counted in the parameter_size bits.
  // Even with the appendix, the method will never take more than 255 parameter slots.
  //
  // This means that given a call site like (List)mh.invoke("foo"),
  // the f1 method has signature '(Ljl/Object;Ljl/invoke/MethodType;)Ljl/Object;',
  // not '(Ljava/lang/String;)Ljava/util/List;'.
  // The fact that String and List are involved is encoded in the MethodType in refs[f2].
  // This allows us to create fewer Methods, while keeping type safety.
  //

  // Store appendix, if any.
  if (has_appendix) {
    const int appendix_index = f2_as_index() + _indy_resolved_references_appendix_offset;
    assert(appendix_index >= 0 && appendix_index < resolved_references->length(), "oob");
    assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
    resolved_references->obj_at_put(appendix_index, appendix());
  }

  // Store MethodType, if any.
  if (has_method_type) {
    const int method_type_index = f2_as_index() + _indy_resolved_references_method_type_offset;
    assert(method_type_index >= 0 && method_type_index < resolved_references->length(), "oob");
    assert(resolved_references->obj_at(method_type_index) == NULL, "init just once");
    resolved_references->obj_at_put(method_type_index, method_type());
  }

  release_set_f1(adapter());  // This must be the last one to set (see NOTE above)!

  // The interpreter assembly code does not check byte_2,
  // but it is used by is_resolved, method_if_resolved, etc.
  set_bytecode_1(invoke_code);
  NOT_PRODUCT(verify(tty));
  if (TraceInvokeDynamic) {
    ttyLocker ttyl;
    this->print(tty, 0);
  }
}
int main(void)
{
    Object* ns = 0;
    esInit(&ns);
    FatFileSystem::initializeConstructor();
    Handle<es::Context> nameSpace(ns);

#ifdef __es__
    Handle<es::Stream> disk = nameSpace->lookup("device/floppy");
#else
    Handle<es::Stream> disk = new VDisk(static_cast<char*>("2hd.img"));
#endif
    long long diskSize;
    diskSize = disk->getSize();
    esReport("diskSize: %lld\n", diskSize);

    Handle<es::FileSystem> fatFileSystem;
    long long freeSpace;
    long long totalSpace;

    fatFileSystem = es::FatFileSystem::createInstance();
    fatFileSystem->mount(disk);
    fatFileSystem->format();
    freeSpace = fatFileSystem->getFreeSpace();
    totalSpace = fatFileSystem->getTotalSpace();
    esReport("Free space %lld, Total space %lld\n", freeSpace, totalSpace);
    {
        Handle<es::Context> root;

        root = fatFileSystem->getRoot();
        long ret = TestFileSystem(root);
        TEST (ret == 0);
        freeSpace = fatFileSystem->getFreeSpace();
        totalSpace = fatFileSystem->getTotalSpace();
        esReport("Free space %lld, Total space %lld\n", freeSpace, totalSpace);
        esReport("\nChecking the file system...\n");
        TEST(fatFileSystem->checkDisk(false));
    }
    fatFileSystem->dismount();
    fatFileSystem = 0;

    fatFileSystem = es::FatFileSystem::createInstance();
    fatFileSystem->mount(disk);
    freeSpace = fatFileSystem->getFreeSpace();
    totalSpace = fatFileSystem->getTotalSpace();
    esReport("Free space %lld, Total space %lld\n", freeSpace, totalSpace);
    esReport("\nChecking the file system...\n");
    TEST(fatFileSystem->checkDisk(false));
    fatFileSystem->dismount();
    fatFileSystem = 0;

    esReport("done.\n\n");
}
static long TestFileSystem(Handle<es::Context>  root)
{
    const char* dirList[] =
    {
        "ディレクトリ",
        "ディレクトリ",
        "a1",
        "a2",
        "a3",
        "a4",
        "a5",
        "a6",
        "a7",
        "a8",
        "a9",
        "a10",
        "a11",
        "a12",
        "a13",
        "a14",
        "a15",
        "a16",

        "@abc",
        "@",
        "_abc",
        "_",
        "`abc",
        "`",
        "~abc",
        "~",
        "+abc",
        "+",
        "=abc",
        "=",
        "-abc",
        "-",
        "1",
        "1a",
        "a",
        "abc_defgh",
        "abc-defgh",
        "bcd",
        "a.b.c",
        "a b c",
        "a                     b                     c",
        "^",
        "^",
        "!",
        "!abc",
        "#",
        "#abc",
        "$",
        "$abc",
        "%",
        "%abc",
        "&",
        "&abc",
        "{}",
        "{abc}",
        ";abc",
        ";",
        ";;;",
        ";;;abc",
        "[]",
        "[abc]",
        ",",
        "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee"
        "ffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjj"
        "kkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnoooooooooo"
        "ppppppppppqqqqqqqqqqrrrrrrrrrrsssssssssstttttttttt"
        "uuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxxxyyyyyyyyyy"
        "zzzzz", // 255
        "...a",
        "..opq",
        ".bcd",
        // ".e.f.g.",
        ".e.f.g",
        // "hij.",
        // "k.l.m.",
        "k.l.m",
        // "rst..",
        // "u..v..w..",
        "u..v..w",
        // "xyz..."
    };

    esReport("Create Directories\n");

    int i;
    for (i = 0; i < sizeof(dirList)/sizeof(dirList[0]); ++i)
    {
        int len = strlen(dirList[i]);
        esReport("create \"%s\" (len %d)\n", dirList[i], len);

        Handle<es::File> file = root->lookup(dirList[i]);
        if (!file)
        {
            file = root->createSubcontext(dirList[i]);
            TEST(file->isDirectory());
            TEST(file->canRead());
            TEST(file->canWrite());
            TEST(!file->isHidden());
            TEST(!file->isFile());
        }
        TEST(file);

        char created[512];
        file->getName(created, sizeof(created));
        TEST(strcmp(created, dirList[i]) == 0);
    }

    Handle<es::File> dir = root->createSubcontext("abc");
    TEST(dir);
    dir = 0;
    dir = root->createSubcontext("abc/def");
    TEST(dir);
    dir = 0;
    dir = root->createSubcontext("abc\\ghi");
    TEST(dir);
    dir = 0;

    Handle<es::Context> abc  = root->lookup("abc");
    TEST(abc);
    Handle<es::Iterator>   iter;
    iter = abc->list("");
    long n = 0;
    while (iter->hasNext())
    {
        char name[1024];
        Handle<es::Binding> binding(iter->next());
        binding->getName(name, sizeof name);
        TEST(strcmp(name, "def") == 0 || strcmp(name, "ghi") == 0);
        ++n;
    }
    TEST(n == 2);

    // create the directory that already exists.
    dir = root->createSubcontext("abc");
    TEST(!dir);

    // check wrong name.
    const char* wrongDirList[] =
    {
        "*",
        "<",
        ">",
        "\"",
        "|",
        ":",
        "?",
        "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee"
        "ffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjj"
        "kkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnoooooooooo"
        "ppppppppppqqqqqqqqqqrrrrrrrrrrsssssssssstttttttttt"
        "uuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxxxyyyyyyyyyy"
        "zzzzzz", // 256,
        "nonexistent/dir",
        "nonexistent\\dir"
    };

    for (i = 0; i < sizeof(wrongDirList)/sizeof(wrongDirList[0]); ++i)
    {
        int len = strlen(wrongDirList[i]);
        esReport("create \"%s\" (len %d)\n", wrongDirList[i], len);

        try
        {
            Handle<es::File> file = root->createSubcontext(wrongDirList[i]);
            TEST(!file);
        }
        catch (SystemException<EACCES>& e)
        {
            TEST(strcmp(wrongDirList[i], "*") == 0 ||
                 strcmp(wrongDirList[i], "<") == 0 ||
                 strcmp(wrongDirList[i], ">") == 0 ||
                 strcmp(wrongDirList[i], "\"") == 0 ||
                 strcmp(wrongDirList[i], "|") == 0 ||
                 strcmp(wrongDirList[i], ":") == 0 ||
                 strcmp(wrongDirList[i], "?") == 0);
        }
        catch (SystemException<ENAMETOOLONG>& e)
        {
            TEST(strcmp(wrongDirList[i],
                "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeee"
                "ffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjj"
                "kkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnoooooooooo"
                "ppppppppppqqqqqqqqqqrrrrrrrrrrsssssssssstttttttttt"
                "uuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxxxyyyyyyyyyy"
                "zzzzzz") == 0);
        }
    }

    return 0;
}
Exemplo n.º 7
0
bool PDFDictionaryDriver::HasInstance(Handle<Value> inObject)
{
	CREATE_ISOLATE_CONTEXT;

	return inObject->IsObject() && HAS_INSTANCE(constructor_template, inObject);
}
Exemplo n.º 8
0
Arquivo: bind.cpp Projeto: Qard/jsgame
Handle<ObjectTemplate> AlutFactory::createAlut(int* pargc, char** argv) {
	HandleScope handle_scope;
	Handle<ObjectTemplate> Alut = ObjectTemplate::New();

	Alut->SetInternalFieldCount(1);

	Alut->SetAccessor(String::NewSymbol("API"), GetALUT_API);
	Alut->SetAccessor(String::NewSymbol("APIENTRY"), GetALUT_APIENTRY);
	Alut->SetAccessor(String::NewSymbol("ATTRIBUTE_DEPRECATED"), GetALUT_ATTRIBUTE_DEPRECATED);
	Alut->SetAccessor(String::NewSymbol("API_MAJOR_VERSION"), GetALUT_API_MAJOR_VERSION);
	Alut->SetAccessor(String::NewSymbol("API_MINOR_VERSION"), GetALUT_API_MINOR_VERSION);
	Alut->SetAccessor(String::NewSymbol("ERROR_NO_ERROR"), GetALUT_ERROR_NO_ERROR);
	Alut->SetAccessor(String::NewSymbol("ERROR_OUT_OF_MEMORY"), GetALUT_ERROR_OUT_OF_MEMORY);
	Alut->SetAccessor(String::NewSymbol("ERROR_INVALID_ENUM"), GetALUT_ERROR_INVALID_ENUM);
	Alut->SetAccessor(String::NewSymbol("ERROR_INVALID_VALUE"), GetALUT_ERROR_INVALID_VALUE);
	Alut->SetAccessor(String::NewSymbol("ERROR_INVALID_OPERATION"), GetALUT_ERROR_INVALID_OPERATION);
	Alut->SetAccessor(String::NewSymbol("ERROR_NO_CURRENT_CONTEXT"), GetALUT_ERROR_NO_CURRENT_CONTEXT);
	Alut->SetAccessor(String::NewSymbol("ERROR_AL_ERROR_ON_ENTRY"), GetALUT_ERROR_AL_ERROR_ON_ENTRY);
	Alut->SetAccessor(String::NewSymbol("ERROR_ALC_ERROR_ON_ENTRY"), GetALUT_ERROR_ALC_ERROR_ON_ENTRY);
	Alut->SetAccessor(String::NewSymbol("ERROR_OPEN_DEVICE"), GetALUT_ERROR_OPEN_DEVICE);
	Alut->SetAccessor(String::NewSymbol("ERROR_CLOSE_DEVICE"), GetALUT_ERROR_CLOSE_DEVICE);
	Alut->SetAccessor(String::NewSymbol("ERROR_CREATE_CONTEXT"), GetALUT_ERROR_CREATE_CONTEXT);
	Alut->SetAccessor(String::NewSymbol("ERROR_MAKE_CONTEXT_CURRENT"), GetALUT_ERROR_MAKE_CONTEXT_CURRENT);
	Alut->SetAccessor(String::NewSymbol("ERROR_DESTROY_CONTEXT"), GetALUT_ERROR_DESTROY_CONTEXT);
	Alut->SetAccessor(String::NewSymbol("ERROR_GEN_BUFFERS"), GetALUT_ERROR_GEN_BUFFERS);
	Alut->SetAccessor(String::NewSymbol("ERROR_BUFFER_DATA"), GetALUT_ERROR_BUFFER_DATA);
	Alut->SetAccessor(String::NewSymbol("ERROR_IO_ERROR"), GetALUT_ERROR_IO_ERROR);
	Alut->SetAccessor(String::NewSymbol("ERROR_UNSUPPORTED_FILE_TYPE"), GetALUT_ERROR_UNSUPPORTED_FILE_TYPE);
	Alut->SetAccessor(String::NewSymbol("ERROR_UNSUPPORTED_FILE_SUBTYPE"), GetALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE);
	Alut->SetAccessor(String::NewSymbol("ERROR_CORRUPT_OR_TRUNCATED_DATA"), GetALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_SINE"), GetALUT_WAVEFORM_SINE);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_SQUARE"), GetALUT_WAVEFORM_SQUARE);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_SAWTOOTH"), GetALUT_WAVEFORM_SAWTOOTH);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_WHITENOISE"), GetALUT_WAVEFORM_WHITENOISE);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_IMPULSE"), GetALUT_WAVEFORM_IMPULSE);
	Alut->SetAccessor(String::NewSymbol("LOADER_BUFFER"), GetALUT_LOADER_BUFFER);
	Alut->SetAccessor(String::NewSymbol("LOADER_MEMORY"), GetALUT_LOADER_MEMORY);

	Alut->Set(String::NewSymbol("init"), FunctionTemplate::New(ALUTInitCallback));
	Alut->Set(String::NewSymbol("initWithoutContext"), FunctionTemplate::New(ALUTInitWithoutContextCallback));
	Alut->Set(String::NewSymbol("exit"), FunctionTemplate::New(ALUTExitCallback));
	Alut->Set(String::NewSymbol("getError"), FunctionTemplate::New(ALUTGetErrorCallback));
	Alut->Set(String::NewSymbol("getErrorString"), FunctionTemplate::New(ALUTGetErrorStringCallback));
	Alut->Set(String::NewSymbol("createBufferFromFile"), FunctionTemplate::New(ALUTCreateBufferFromFileCallback));
	Alut->Set(String::NewSymbol("createBufferFromFileImage"), FunctionTemplate::New(ALUTCreateBufferFromFileImageCallback));
	Alut->Set(String::NewSymbol("createBufferHelloWorld"), FunctionTemplate::New(ALUTCreateBufferHelloWorldCallback));
	Alut->Set(String::NewSymbol("createBufferWaveform"), FunctionTemplate::New(ALUTCreateBufferWaveformCallback));
	Alut->Set(String::NewSymbol("loadMemoryFromFile"), FunctionTemplate::New(ALUTLoadMemoryFromFileCallback));
	Alut->Set(String::NewSymbol("loadMemoryFromFileImage"), FunctionTemplate::New(ALUTLoadMemoryFromFileImageCallback));
	Alut->Set(String::NewSymbol("loadMemoryHelloWorld"), FunctionTemplate::New(ALUTLoadMemoryHelloWorldCallback));
	Alut->Set(String::NewSymbol("loadMemoryWaveform"), FunctionTemplate::New(ALUTLoadMemoryWaveformCallback));
	Alut->Set(String::NewSymbol("getMIMETypes"), FunctionTemplate::New(ALUTGetMIMETypesCallback));
	Alut->Set(String::NewSymbol("getMajorVersion"), FunctionTemplate::New(ALUTGetMajorVersionCallback));
	Alut->Set(String::NewSymbol("getMinorVersion"), FunctionTemplate::New(ALUTGetMinorVersionCallback));
	Alut->Set(String::NewSymbol("sleep"), FunctionTemplate::New(ALUTSleepCallback));
	Alut->Set(String::NewSymbol("loadWAVFile"), FunctionTemplate::New(ALUTLoadWAVFileCallback));
	Alut->Set(String::NewSymbol("loadWAVMemory"), FunctionTemplate::New(ALUTLoadWAVMemoryCallback));
	Alut->Set(String::NewSymbol("loadWAVFile"), FunctionTemplate::New(ALUTLoadWAVFileCallback));
	Alut->Set(String::NewSymbol("loadWAVMemory"), FunctionTemplate::New(ALUTLoadWAVMemoryCallback));
	Alut->Set(String::NewSymbol("unloadWAV"), FunctionTemplate::New(ALUTUnloadWAVCallback));

	// Again, return the result through the current handle scope.
	return handle_scope.Close(Alut);
}	
Exemplo n.º 9
0
bool
JavaScriptShared::fromDescriptor(JSContext* cx, Handle<PropertyDescriptor> desc,
                                 PPropertyDescriptor* out)
{
    out->attrs() = desc.attributes();
    if (!toVariant(cx, desc.value(), &out->value()))
        return false;

    if (!toObjectOrNullVariant(cx, desc.object(), &out->obj()))
        return false;

    if (!desc.getter()) {
        out->getter() = 0;
    } else if (desc.hasGetterObject()) {
        JSObject* getter = desc.getterObject();
        ObjectVariant objVar;
        if (!toObjectVariant(cx, getter, &objVar))
            return false;
        out->getter() = objVar;
    } else {
        MOZ_ASSERT(desc.getter() != JS_PropertyStub);
        out->getter() = UnknownPropertyOp;
    }

    if (!desc.setter()) {
        out->setter() = 0;
    } else if (desc.hasSetterObject()) {
        JSObject* setter = desc.setterObject();
        ObjectVariant objVar;
        if (!toObjectVariant(cx, setter, &objVar))
            return false;
        out->setter() = objVar;
    } else {
        MOZ_ASSERT(desc.setter() != JS_StrictPropertyStub);
        out->setter() = UnknownPropertyOp;
    }

    return true;
}
Exemplo n.º 10
0
void V8Script::run(ShapeManager2d& pb) {
	
	isolate->Enter();
	
	// Create a stack-allocated handle scope.
	HandleScope handle_scope(Isolate::GetCurrent());
	
	Handle<ObjectTemplate> global = ObjectTemplate::New();
	/*
	global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "__buffer__"), External::New(&pb));
	
	auto color = [](const v8::FunctionCallbackInfo<v8::Value>& args) -> Handle<Value> {
		unsigned int x = args[0]->Uint32Value();
		unsigned int y = args[1]->Uint32Value();
		
		Local<Value> funcObj = args.Callee()->Get(String::NewFromUtf8(Isolate::GetCurrent(), "__buffer"));
		Local<External> wrap = Local<External>::Cast(funcObj);
		void* ptr = wrap->Value();
		
		Local<Object> obj = color_templ->NewInstance();
		obj->SetInternalField(0, External::New(&(*static_cast<PixelBuffer*>(ptr))(x, y)));
		args.GetReturnValue().Set(obj);
	};
	
	Local<FunctionTemplate> colorFuncTemplate = FunctionTemplate::New(Isolate::GetCurrent(), color);
	colorFuncTemplate->Set(String::NewFromUtf8(Isolate::GetCurrent(), "__buffer"), External::New(&pb));*/
	
	Local<External> shapeManagerWrap = External::New(Isolate::GetCurrent(), static_cast<void*>(&pb));
	
	Local<FunctionTemplate> makeTriangleTemplate = FunctionTemplate::New(Isolate::GetCurrent(), makeTriangle);
	makeTriangleTemplate->Set(Isolate::GetCurrent(), shapeManagerStr.c_str(), shapeManagerWrap);
	Local<FunctionTemplate> makeLineTemplate = FunctionTemplate::New(Isolate::GetCurrent(), makeLine);
	makeLineTemplate->Set(Isolate::GetCurrent(), shapeManagerStr.c_str(), shapeManagerWrap);
	Local<FunctionTemplate> makeQuadTemplate = FunctionTemplate::New(Isolate::GetCurrent(), makeQuad);
	makeQuadTemplate->Set(Isolate::GetCurrent(), shapeManagerStr.c_str(), shapeManagerWrap);
	Local<FunctionTemplate> frameWaitTemplate = FunctionTemplate::New(Isolate::GetCurrent(), frameWait);
	frameWaitTemplate->Set(Isolate::GetCurrent(), shapeManagerStr.c_str(), shapeManagerWrap);
	
	//Local<FunctionTemplate> getShapeTemplate = FunctionTemplate::New(Isolate::GetCurrent(), getShape);
	//getShapeTemplate->Set(shapeManagerStr.c_str(), External::New(&pb));
	
	// Return an empty result if there was an error creating the array.
	/*
	if (array.IsEmpty()) {
		return Handle<Array>();
	}*/
	
	// Fill out the values
	global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "makeTriangle"), makeTriangleTemplate);
	global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "makeLine"), makeLineTemplate);
	global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "makeQuad"), makeQuadTemplate);
	global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "frameWait"), frameWaitTemplate);
	global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "getMouseX"), FunctionTemplate::New(Isolate::GetCurrent(), getMouseX));
	global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "getMouseY"), FunctionTemplate::New(Isolate::GetCurrent(), getMouseY));
	
	//global->Set(String::NewFromUtf8(Isolate::GetCurrent(), "shape"), getShapeTemplate);
	
	// Create a new context.
	Handle<Context> context = Context::New(Isolate::GetCurrent(), NULL, global);
	
	// Enter the created context for compiling and
	// running the hello world script. 
	Context::Scope context_scope(context);
	/*
	// Create a new empty array.
	Handle<Array> array = Array::New(pb.maxX());
	
	for(unsigned int x = 0; x < pb.maxX(); x++) {
		Handle<Array> line = Array::New(pb.maxY());
		if(!line.IsEmpty()) {
			for(unsigned int y = 0; y < pb.maxY(); y++) {
				Local<Object> obj = color_templ->NewInstance();
				obj->SetInternalField(0, External::New(&pb(x, y)));
				line->Set(y, obj);
			}
		}
		array->Set(x, line);
	}
	
	context->Global()->Set(String::NewFromUtf8(Isolate::GetCurrent(), "color"), array);*/
	
	
	// Create a string containing the JavaScript source code.
	Handle<String> source = String::NewFromUtf8(Isolate::GetCurrent(), program.c_str());
	
	// Compile the source code.
	Handle<Script> script = Script::Compile(source);
	
	// Run the script to get the result.
	//while(true) {
		//Handle<Value> result = script->Run();
		script->Run();
		//SDL_Delay(1);
		//pb.clear();
	//}
	
	isolate->Exit();
}
Exemplo n.º 11
0
    int V8Scope::type( const char *field ){
        V8_SIMPLE_HEADER
        Handle<Value> v = get( field );
        if ( v->IsNull() )
            return jstNULL;
        if ( v->IsUndefined() )
            return Undefined;
        if ( v->IsString() )
            return String;
        if ( v->IsFunction() )
            return Code;
        if ( v->IsArray() )
            return Array;
        if ( v->IsBoolean() )
            return Bool;
        if ( v->IsInt32() )
            return NumberInt;
        if ( v->IsNumber() )
            return NumberDouble;
        if ( v->IsExternal() ){
            uassert( 10230 ,  "can't handle external yet" , 0 );
            return -1;
        }
        if ( v->IsDate() )
            return Date;
        if ( v->IsObject() )
            return Object;

        throw UserException( 12509, (string)"don't know what this is: " + field );
    }
Exemplo n.º 12
0
BiasedLocking::Condition BiasedLocking::revoke_and_rebias(Handle obj, bool attempt_rebias, TRAPS) {
  assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint");

  // We can revoke the biases of anonymously-biased objects
  // efficiently enough that we should not cause these revocations to
  // update the heuristics because doing so may cause unwanted bulk
  // revocations (which are expensive) to occur.
  markOop mark = obj->mark();
  if (mark->is_biased_anonymously() && !attempt_rebias) {
    // We are probably trying to revoke the bias of this object due to
    // an identity hash code computation. Try to revoke the bias
    // without a safepoint. This is possible if we can successfully
    // compare-and-exchange an unbiased header into the mark word of
    // the object, meaning that no other thread has raced to acquire
    // the bias of the object.
    markOop biased_value       = mark;
    markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
    markOop res_mark = (markOop) Atomic::cmpxchg_ptr(unbiased_prototype, obj->mark_addr(), mark);
    if (res_mark == biased_value) {
      return BIAS_REVOKED;
    }
  } else if (mark->has_bias_pattern()) {
    Klass* k = obj->klass();
    markOop prototype_header = k->prototype_header();
    if (!prototype_header->has_bias_pattern()) {
      // This object has a stale bias from before the bulk revocation
      // for this data type occurred. It's pointless to update the
      // heuristics at this point so simply update the header with a
      // CAS. If we fail this race, the object's bias has been revoked
      // by another thread so we simply return and let the caller deal
      // with it.
      markOop biased_value       = mark;
      markOop res_mark = (markOop) Atomic::cmpxchg_ptr(prototype_header, obj->mark_addr(), mark);
      assert(!(*(obj->mark_addr()))->has_bias_pattern(), "even if we raced, should still be revoked");
      return BIAS_REVOKED;
    } else if (prototype_header->bias_epoch() != mark->bias_epoch()) {
      // The epoch of this biasing has expired indicating that the
      // object is effectively unbiased. Depending on whether we need
      // to rebias or revoke the bias of this object we can do it
      // efficiently enough with a CAS that we shouldn't update the
      // heuristics. This is normally done in the assembly code but we
      // can reach this point due to various points in the runtime
      // needing to revoke biases.
      if (attempt_rebias) {
        assert(THREAD->is_Java_thread(), "");
        markOop biased_value       = mark;
        markOop rebiased_prototype = markOopDesc::encode((JavaThread*) THREAD, mark->age(), prototype_header->bias_epoch());
        markOop res_mark = (markOop) Atomic::cmpxchg_ptr(rebiased_prototype, obj->mark_addr(), mark);
        if (res_mark == biased_value) {
          return BIAS_REVOKED_AND_REBIASED;
        }
      } else {
        markOop biased_value       = mark;
        markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
        markOop res_mark = (markOop) Atomic::cmpxchg_ptr(unbiased_prototype, obj->mark_addr(), mark);
        if (res_mark == biased_value) {
          return BIAS_REVOKED;
        }
      }
    }
  }

  HeuristicsResult heuristics = update_heuristics(obj(), attempt_rebias);
  if (heuristics == HR_NOT_BIASED) {
    return NOT_BIASED;
  } else if (heuristics == HR_SINGLE_REVOKE) {
    Klass *k = obj->klass();
    markOop prototype_header = k->prototype_header();
    if (mark->biased_locker() == THREAD &&
        prototype_header->bias_epoch() == mark->bias_epoch()) {
      // A thread is trying to revoke the bias of an object biased
      // toward it, again likely due to an identity hash code
      // computation. We can again avoid a safepoint in this case
      // since we are only going to walk our own stack. There are no
      // races with revocations occurring in other threads because we
      // reach no safepoints in the revocation path.
      // Also check the epoch because even if threads match, another thread
      // can come in with a CAS to steal the bias of an object that has a
      // stale epoch.
      ResourceMark rm;
      if (TraceBiasedLocking) {
        tty->print_cr("Revoking bias by walking my own stack:");
      }
      BiasedLocking::Condition cond = revoke_bias(obj(), false, false, (JavaThread*) THREAD);
      ((JavaThread*) THREAD)->set_cached_monitor_info(NULL);
      assert(cond == BIAS_REVOKED, "why not?");
      return cond;
    } else {
      VM_RevokeBias revoke(&obj, (JavaThread*) THREAD);
      VMThread::execute(&revoke);
      return revoke.status_code();
    }
  }

  assert((heuristics == HR_BULK_REVOKE) ||
         (heuristics == HR_BULK_REBIAS), "?");
  VM_BulkRevokeBias bulk_revoke(&obj, (JavaThread*) THREAD,
                                (heuristics == HR_BULK_REBIAS),
                                attempt_rebias);
  VMThread::execute(&bulk_revoke);
  return bulk_revoke.status_code();
}
Exemplo n.º 13
0
bool PDFBooleanDriver::HasInstance(Handle<Value> inObject)
{
    return inObject->IsObject() &&
    constructor_template->HasInstance(inObject->ToObject());
}