You can only set primitive values and other templates on templates. If you
want a non-primitive value, you can either use a "native data property" or
install a getter / setter. V8 5.2 and later will CHECK() if you try to set
anything else.

On Fri, May 6, 2016 at 6:53 AM [email protected] <[email protected]>
wrote:

> Please see the following code. I want to add a JS Date to a Object
> available in the global object. This works with a older version
> (4.9.385.28) but fails with (5.0.71.33)... see output
>
> g++ -I/usr/local core.c -o testCore -ldl -pthread -std=c++0x -lv8
> -lv8_libplatform -lv8_libbase
>
> core.c:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include "include/libplatform/libplatform.h"
> #include "include/v8.h"
> #include "time.h"
>
> using namespace v8;
>
> class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator
> {
> public:
> virtual void* Allocate(size_t length) { void* data =
> AllocateUninitialized(length); return data == NULL ? data : memset(data, 0,
> length); }
> virtual void* AllocateUninitialized(size_t length) { return
> malloc(length); }
> virtual void Free(void* data, size_t) { free(data); }
> };
>
> int main(int argc, char* argv[])
> {
> // Initialize V8.
> V8::InitializeICU();
> V8::InitializeExternalStartupData(argv[0]);
> Platform* platform = platform::CreateDefaultPlatform();
> V8::InitializePlatform(platform);
> V8::Initialize();
>
> // Create a new Isolate and make it the current one.
> ArrayBufferAllocator allocator;
> Isolate::CreateParams create_params;
> create_params.array_buffer_allocator = &allocator;
> Isolate* isolate = Isolate::New(create_params);
> Isolate::Scope isolate_scope(isolate);
>
> // Create a stack-allocated handle scope.
> HandleScope handle_scope(isolate);
>
> Local<Context> context =
> Context::New(isolate,NULL,ObjectTemplate::New(isolate));
> Context::Scope context_scope(context);
>
> Local<ObjectTemplate> activity = ObjectTemplate::New(isolate);
> //
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> // ************************ This line breaks the NewInstance() call
> (5.0.71.33) works in (4.9.385.28) *****************************
> //
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> activity->Set        (String::NewFromUtf8(isolate, "createddate",
> NewStringType::kNormal).ToLocalChecked(),
> Date::New(isolate,time(NULL)*1000.0));
>
> Local<Object> activityInst = activity->NewInstance();
> context->Global()->Set(String::NewFromUtf8(isolate, "activity",
> NewStringType::kNormal).ToLocalChecked(), activityInst);
>
> return 0;
> }
>
>
> output:
>
> #
> # Fatal error in ../src/heap/heap.cc, line 3564
> # Check failed: map->instance_type() == JS_REGEXP_TYPE ||
> map->instance_type() == JS_OBJECT_TYPE || map->instance_type() ==
> JS_ARRAY_TYPE.
> #
>
> ==== C stack trace ===============================
>
> 1: V8_Fatal
> 2: v8::internal::Heap::CopyJSObject(v8::internal::JSObject*,
> v8::internal::AllocationSite*)
> 3:
> v8::internal::Factory::CopyJSObjectWithAllocationSite(v8::internal::Handle<v8::internal::JSObject>,
> v8::internal::Handle<v8::internal::AllocationSite>)
> 4: v8::internal::JSObjectWalkVisitor<v8::internal::DummyContextObject,
> (v8::internal::BoilerplateKind)1>::StructureWalk(v8::internal::Handle<v8::internal::JSObject>)
> 5: v8::internal::JSObjectWalkVisitor<v8::internal::DummyContextObject,
> (v8::internal::BoilerplateKind)1>::StructureWalk(v8::internal::Handle<v8::internal::JSObject>)
> 6:
> v8::internal::JSObject::DeepCopyApiBoilerplate(v8::internal::Handle<v8::internal::JSObject>)
> 7: v8::internal::(anonymous
> namespace)::InstantiateObject(v8::internal::Isolate*,
> v8::internal::Handle<v8::internal::ObjectTemplateInfo>, bool)
> 8:
> v8::internal::ApiNatives::InstantiateObject(v8::internal::Handle<v8::internal::ObjectTemplateInfo>)
> 9: v8::ObjectTemplate::NewInstance(v8::Local<v8::Context>)
> 10: main
> 11: start
> 12: 0x1
> Illegal instruction
>
> --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to