Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using the v8 in the program of VC++.

I used a shell.cc of sample files v8_shell of v8 source, modify the source code.

I try to output the value of the result of executing the javascript read the js file.

Function, use the Function Template, and outputs the value of the results. However variable are not output the value of the results.

I to receiving the value of the variable, knows that it is necessary to use the Accessor.

Homepage

I was referring to the home page of the link, but the description is not the attitude.

An example of how it is used is insufficient.

Portion to be a problem is the location.href of javascript.

Using the Accessor, but will try to output the url value, an error occurs.

The following is a source code that I have created.

Complete source -> Test V8shell · GitHub

Compilation is not a problem, but not in the normal run.

Operation of the program is output to have been stopped.
C++
// Creates a new execution environment containing the built-in
// functions.
v8::Local<v8::Context> CreateShellContext(v8::Isolate* isolate) {
    // Create a template for the global object.
    v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);

    // Bind the global 'print' function to the C++ Print callback.
    global->Set(
        v8::String::NewFromUtf8(isolate, "print", v8::NewStringType::kNormal)
        .ToLocalChecked(),
        v8::FunctionTemplate::New(isolate, Print));
    // Bind the global 'read' function to the C++ Read callback.
    global->Set(v8::String::NewFromUtf8(
        isolate, "read", v8::NewStringType::kNormal).ToLocalChecked(),
        v8::FunctionTemplate::New(isolate, Read));
    // Bind the global 'load' function to the C++ Load callback.
    global->Set(v8::String::NewFromUtf8(
        isolate, "load", v8::NewStringType::kNormal).ToLocalChecked(),
        v8::FunctionTemplate::New(isolate, Load));
    // Bind the 'quit' function
    global->Set(v8::String::NewFromUtf8(
        isolate, "quit", v8::NewStringType::kNormal).ToLocalChecked(),
        v8::FunctionTemplate::New(isolate, Quit));
    // Bind the 'version' function
    global->Set(
        v8::String::NewFromUtf8(isolate, "version", v8::NewStringType::kNormal)
        .ToLocalChecked(),
        v8::FunctionTemplate::New(isolate, Version));
    // Bind the 'Alert' function
    global->Set(
        v8::String::NewFromUtf8(isolate, "alert", v8::NewStringType::kNormal)
        .ToLocalChecked(),
        v8::FunctionTemplate::New(isolate, Alert));
    // Bind the 'Prompt' function
    global->Set(
        v8::String::NewFromUtf8(isolate, "prompt", v8::NewStringType::kNormal)
        .ToLocalChecked(),
        v8::FunctionTemplate::New(isolate, Prompt));
    // Bind the 'location' function
    v8::Local<v8::ObjectTemplate> MLTempl = MakeLocationObjectTemplate(isolate);
    v8::Local<v8::Object> MLObject = MLTempl->NewInstance();
    global->Set(
        v8::String::NewFromUtf8(isolate, "location", v8::NewStringType::kInternalized)
        .ToLocalChecked(), MLObject);

    return v8::Context::New(isolate, NULL, global);
}

Problem is, in the above code v8 :: Local MLObject = MLTempl-> NewInstance (); occur in the part of .

And try to keep track of the error, in the end, an error occurs in the next part.

110 line

C++
NATIVE_CONTEXT_FIELDS (NATIVE_CONTEXT_FIELD_ACCESSOR)

access error of isolate-inl.h is output.

how do i do this?

What I have tried:

google refer to the website, I tried to fix a look at the source of the previous version.
Posted
Comments
KarstenK 1-Sep-16 9:15am    
Increase the life time of _ALL_ objects. Like make the MLTempl a class member so it can init before the call. Look in the source file or write the author.
Kito87 1-Sep-16 22:26pm    
Thank you with the answer. Before calling the init (), do I MLTeml class is called? Refer to that comment, consider again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900