37 using ::v8::ObjectTemplate;
44 using ::v8::Extension;
46 static void handle_property(Local<String>
name,
52 static void handle_property_2(Local<String> name,
71 fun_templ->InstanceTemplate()->SetAccessor(v8_str(
"foo"), handle_property);
72 Local<v8::FunctionTemplate> getter_templ =
74 getter_templ->SetLength(0);
76 InstanceTemplate()->SetAccessorProperty(v8_str(
"bar"), getter_templ);
77 fun_templ->InstanceTemplate()->
78 SetNativeDataProperty(v8_str(
"instance_foo"), handle_property);
79 fun_templ->SetNativeDataProperty(v8_str(
"object_foo"), handle_property_2);
80 Local<Function> fun = fun_templ->GetFunction();
81 env->
Global()->Set(v8_str(
"Fun"), fun);
85 getter = v8_compile(
"var obj = new Fun(); obj.instance_foo;");
86 CHECK_EQ(900, getter->Run()->Int32Value());
87 setter = v8_compile(
"obj.instance_foo = 901;");
88 CHECK_EQ(901, setter->Run()->Int32Value());
89 getter = v8_compile(
"obj.bar;");
90 CHECK_EQ(907, getter->Run()->Int32Value());
91 setter = v8_compile(
"obj.bar = 908;");
92 CHECK_EQ(908, setter->Run()->Int32Value());
94 getter = v8_compile(
"Fun.object_foo;");
95 CHECK_EQ(902, getter->Run()->Int32Value());
96 setter = v8_compile(
"Fun.object_foo = 903;");
97 CHECK_EQ(903, setter->Run()->Int32Value());
101 static void GetIntValue(Local<String> property,
110 static void SetIntValue(Local<String> property,
115 *field = value->Int32Value();
128 v8_str(
"foo"), GetIntValue, SetIntValue,
131 v8_str(
"bar"), GetIntValue, SetIntValue,
134 v8_str(
"baz"), GetIntValue, SetIntValue,
137 v8_compile(
"foo = (++bar) + baz")->Run();
143 static int x_register[2] = {0, 0};
148 static void XGetter(
const Info& info,
int offset) {
151 CHECK_EQ(isolate, info.GetIsolate());
153 info.GetReturnValue().Set(v8_num(x_register[offset]));
157 static void XGetter(Local<String> name,
171 static void XSetter(Local<Value> value,
const Info& info,
int offset) {
173 CHECK_EQ(isolate, info.GetIsolate());
176 x_register[offset] = value->Int32Value();
177 info.GetReturnValue().Set(v8_num(-1));
181 static void XSetter(Local<String> name,
184 XSetter(value, info, 0);
190 XSetter(info[0], info, 1);
204 context->
Global()->Set(v8_str(
"holder"), x_holder);
206 context->
Global()->Set(v8_str(
"obj"), x_receiver);
208 "obj.__proto__ = holder;"
212 "for (var j = 0; j < 10; j++) {"
214 " result.push(holder.x0 = i);"
215 " result.push(obj.x0);"
216 " result.push(holder.x1 = i + 1);"
217 " result.push(obj.x1);"
218 " result.push(holder[key_0] = i + 2);"
219 " result.push(obj[key_0]);"
220 " result.push(holder[key_1] = i + 3);"
221 " result.push(obj[key_1]);"
225 for (
int i = 0; i < 80; i++) {
232 static void AccessorProhibitsOverwritingGetter(
244 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
245 templ->SetAccessor(v8_str(
"x"),
246 AccessorProhibitsOverwritingGetter,
251 Local<v8::Object> instance = templ->NewInstance();
252 context->
Global()->Set(v8_str(
"obj"), instance);
253 Local<Value> value = CompileRun(
254 "obj.__defineGetter__('x', function() { return false; });"
256 CHECK(value->BooleanValue());
258 "var setter_called = false;"
259 "obj.__defineSetter__('x', function() { setter_called = true; });"
262 CHECK(!value->BooleanValue());
265 "obj2.__proto__ = obj;"
266 "obj2.__defineGetter__('x', function() { return false; });"
268 CHECK(value->BooleanValue());
270 "var setter_called = false;"
272 "obj2.__proto__ = obj;"
273 "obj2.__defineSetter__('x', function() { setter_called = true; });"
276 CHECK(!value->BooleanValue());
281 static void HandleAllocatingGetter(
285 for (
int i = 0; i < C; i++)
296 obj->
SetAccessor(v8_str(
"one"), HandleAllocatingGetter<1>);
297 obj->
SetAccessor(v8_str(
"many"), HandleAllocatingGetter<1024>);
305 "for (var i = 0; i < 1000; i++) {"
312 CHECK_EQ(count_before, count_after);
315 static void CheckAccessorArgsCorrect(
342 CheckAccessorArgsCorrect,
350 for (
int i = 0; i < 10; i++) {
351 Local<Value> result = scr->Run();
352 CHECK(!result.IsEmpty());
357 static void EmptyGetter(Local<String> name,
359 CheckAccessorArgsCorrect(name, info);
361 CheckAccessorArgsCorrect(name, info);
377 for (
int i = 0; i < 10; i++) {
378 Local<Value> result = scr->Run();
398 for (
int i = 0; i < 2; i++) {
399 Local<Value> result = scr->Run();
406 CheckAccessorArgsCorrect,
414 for (
int i = 0; i < 10; i++) {
415 Local<Value> result = scr->Run();
416 CHECK(!result.IsEmpty());
422 static void ThrowingGetAccessor(
426 info.
GetIsolate()->ThrowException(v8_str(
"g"));
430 static void ThrowingSetAccessor(Local<String> name,
452 result = Script::Compile(v8_str(
454 "for (var i = 0; i < 5; i++) {"
455 " try { obj.x; } catch (e) { result += e; }"
456 "}; result"))->Run();
459 result = Script::Compile(String::NewFromUtf8(
462 "for (var i = 0; i < 5; i++) {"
463 " try { obj.x = i; } catch (e) { result += e; }"
464 "}; result"))->Run();
469 static void AllocGetter(Local<String> name,
483 Script::Compile(String::NewFromUtf8(
486 "for (var i = 0; i < 2048; i++) {"
487 " var result = obj.xxx;"
494 static void StackCheck(Local<String> name,
497 for (
int i = 0; !iter.done(); i++) {
499 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT));
501 CHECK(code->IsCode());
515 reinterpret_cast<i::Isolate*>(isolate));
518 Script::Compile(String::NewFromUtf8(
523 "for (var i = 0; i < 100; i++) {"
529 static void AllocateHandles(Local<String> name,
550 "for (var i = 0; i < 4; i++)"
559 array->
Set(0, v8_str(
"regress"));
580 CHECK(CompileRun(
"JSON.stringify(obj)")->Equals(expected));
590 CHECK(expected_current_context == info.
GetIsolate()->GetCurrentContext());
591 CHECK(expected_calling_context == info.
GetIsolate()->GetCallingContext());
601 switch_context->
Global()->Set(v8_str(
"fun"), fun);
603 expected_current_context = env.
local();
604 expected_calling_context = switch_context.
local();
606 "var o = Object.create(null, { n: { get:fun } });"
607 "for (var i = 0; i < 10; i++) o.n;");
618 "Object.defineProperty(this.__proto__, 'x', {"
619 " get : function() { return this; },"
620 " set : function() { set_value = this; }"
622 "function getter() { return x; }"
623 "function setter() { x = 1; }"
624 "for (var i = 0; i < 4; i++) { getter(); setter(); }");
void SetAccessor(Handle< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
static V8_INLINE Local< T > New(Isolate *isolate, Handle< T > that)
#define CHECK_EQ(expected, value)
void CollectAllGarbage(int flags, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
V8_INLINE Isolate * GetIsolate() const
Local< Value > Get(Handle< Value > key)
Local< Object > NewInstance()
V8_INLINE ReturnValue< T > GetReturnValue() const
void JSONStringifyGetter(Local< String > name, const v8::PropertyCallbackInfo< v8::Value > &info)
V8_INLINE int Length() const
Local< ObjectTemplate > InstanceTemplate()
V8_INLINE Local< Object > Holder() const
static Local< Integer > New(Isolate *isolate, int32_t value)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
v8::Isolate * GetIsolate()
void SetNamedPropertyHandler(NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter=0, NamedPropertyQueryCallback query=0, NamedPropertyDeleterCallback deleter=0, NamedPropertyEnumeratorCallback enumerator=0, Handle< Value > data=Handle< Value >())
HANDLE HANDLE LPSTACKFRAME64 StackFrame
static int NumberOfHandles(Isolate *isolate)
V8_INLINE Isolate * GetIsolate() const
static const int kNoGCFlags
static Local< External > New(Isolate *isolate, void *value)
V8_INLINE Local< Object > Holder() const
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
int32_t Int32Value() const
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *script_data=NULL)
static V8_INLINE Handle< T > Cast(Handle< S > that)
V8_INLINE ReturnValue< T > GetReturnValue() const
static Local< Array > New(Isolate *isolate, int length=0)
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
V8_INLINE Handle< Primitive > Undefined(Isolate *isolate)
static Local< Object > New(Isolate *isolate)
V8_INLINE Local< Object > This() const
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
const int kHandleBlockSize
void JSONStringifyEnumerator(const v8::PropertyCallbackInfo< v8::Array > &info)
static void ClearMentionedObjectCache(Isolate *isolate)
void SetAccessorProperty(Local< String > name, Local< FunctionTemplate > getter=Local< FunctionTemplate >(), Local< FunctionTemplate > setter=Local< FunctionTemplate >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT)
v8::Local< v8::Context > local()
static Local< Function > New(Isolate *isolate, FunctionCallback callback, Local< Value > data=Local< Value >(), int length=0)
V8_INLINE Local< Value > Data() const
THREADED_TEST(PropertyHandler)
bool Set(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
static v8::Isolate * isolate()
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)